我嘗試從csproj文件獲取所有dll名稱,但無法獲取任何內容! 所以,我試圖擺脫的ItemGroup標籤元素人與LIQ查詢:通過c#解析csproj - 無法解析ItemGroup
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。我切一些unusfull文本))
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="MyProject1" />
<Reference Include="MyProject2" />
<Reference Include="MyProject3" />
</ItemGroup>
</Project>
請幫我弄名稱的列表!我做錯了什麼?
謝謝。
相關(但不是一個笨蛋)http://stackoverflow.com/q/3745029/492 –