What is a better way to retrieve this XElement when reading a csproj with XDocument?
I'm adding files to the a cs project outside of vs.net (images, css, etc, files outside our group but are necessary to Publish). I'm loading the csproj and querying for the ItemGroup tha开发者_开发问答t contains the "Content" nodes.
XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
XDocument projectDocument = XDocument.Load("someproject.csproj");
var itemGroup = projectDocument.Element(msbuild + "Project")
.Elements(msbuild + "ItemGroup")
.Descendants()
.Where(x => x.Name == msbuild +"Content")
.First().Parent;
Is there a better way to get this group?
Thank you.
You could do it like this:
var itemGroup =
projectDocument.Element(msbuild + "Project")
.Elements(msbuild + "ItemGroup")
.Where(x => x.Descendants()
.Any(y => y.Name == msbuild +"Content")
)
.FirstOrDefault();
精彩评论