通过c#解析csproj – 无法解析ItemGroup
我试图从csproj文件中获取所有的dll名称,但无法得到任何东西! 所以,我尝试使用liq查询从ItemGroup标签获取al元素:
var elem = doc.Descendants("Project").Where(t => t.Attribute("ToolsVersion")!=null) .Elements("ItemGroup").Elements("Reference").Where(r => r.Attribute("Include") != null); var attrs = elem.Attributes(); Console.WriteLine(attrs.Count()); foreach (var e in attrs) { Console.WriteLine(e); }
这是我的xml csproj文件。 我剪了一些不完整的文字))
icon.ico 4.0
请帮我拿这个名单! 我做错了什么?
谢谢。
你忽略了这个:
xmlns="https://schemas.microsoft.com/developer/msbuild/2003"
这为后代设置了默认命名空间。 所以你要:
上述就是C#学习教程:通过c#解析csproj – 无法解析ItemGroup分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
XNamespace ns = "https://schemas.microsoft.com/developer/msbuild/2003"; var elem = doc.Descendants(ns + "Project") .Where(t => t.Attribute("ToolsVersion")!=null) .Elements(ns + "ItemGroup") .Elements(ns + "Reference") .Where(r => r.Attribute("Include") != null);
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/951988.html