开发者

Updating a *.CSPROJ using MSBUILD API

Based on question : Reading a *.CSPROJ file in C#

I have code to extract some properties out of a *.csproj file, along the lines of :

Project project = new Project();

var Property001=
            from pg in project.PropertyGroups.Cast<BuildPropertyGroup>()
            from item in pg.Cast<BuildProperty>()
  开发者_运维问答          where item.Name == "Property001"
            select item.Value.ToString();

This works fine, but the next question is how do I update the property using LINQ as well?


You could use LINQ to fetch the property item - rather than just the value - to update:

var Property001item =
        (from pg in project.PropertyGroups.Cast<BuildPropertyGroup>()
        from item in pg.Cast<BuildProperty>()
        where item.Name == "Property001"
        select item).FirstOrDefault();
if (Property001item != null)
{
    Property001item.Value = "MyNewValue";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜