来自 MSBUILD 的程序集名称
我正在开发一个应用程序,它读取 MSBUILD 文件( *.csproj )以提取各种信息。此处的上一个问题表明我可以通过以下方式获取正在使用的资源文件
Project project = new Project();
project.Load(fullPathName);
var embeddedResources =
from grp in project.ItemGroups.Cast<BuildItemGroup>()
from item in grp.Cast<BuildItem>()
where item.Name == "EmbeddedResource"
select item;
现在我想获取项目的程序集名称。我最初在“BuildProperyGroup”中查找“Name = 'AssemblyName”的“BuildProperty”时,
我在第一个障碍中失败了
var test =
from grp in project.ItemGroups.Cast<BuildProperyGroup>()
,因为转换无效。
关于我哪里出错的任何线索..
我最终得到的解决方案如下
var PropG =
from pg in project.PropertyGroups.Cast<BuildPropertyGroup>()
from item in pg.Cast<BuildProperty>()
where item.Name == "AssemblyName"
select item.Value.ToString();
I am developing an app that reads a MSBUILD file ( *.csproj ) to pull out various bits of information. A previous question on here revealed that I can get the resource files being used in the following manner
Project project = new Project();
project.Load(fullPathName);
var embeddedResources =
from grp in project.ItemGroups.Cast<BuildItemGroup>()
from item in grp.Cast<BuildItem>()
where item.Name == "EmbeddedResource"
select item;
Now I want to get the assembly name for the project. My initial to look in the "BuildProperyGroup" for a "BuildProperty" with "Name = 'AssemblyName"
I fell at the first hurdle
var test =
from grp in project.ItemGroups.Cast<BuildProperyGroup>()
fails with an invalid cast.
Any clues as to where I am going wrong..
The solution I ended up with is as follows
var PropG =
from pg in project.PropertyGroups.Cast<BuildPropertyGroup>()
from item in pg.Cast<BuildProperty>()
where item.Name == "AssemblyName"
select item.Value.ToString();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
项目组 通常用于文件集合(例如
Compile
组中的所有.cs
文件)。听起来您想在项目的 PropertyGroups 集合。ItemsGroups are for collections of files, generally (such as all the
.cs
files in theCompile
group). It sounds like you want to be poking around in the project's PropertyGroups collection.