Last active
January 10, 2017 04:03
-
-
Save lindexi/813e4b7111c16ac7b8a5149f44226e30 to your computer and use it in GitHub Desktop.
Uwp 获取csproj 所有文件,并获取文件生成选项. Uwp Get all the files in the *.csproj.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 获取csproj 所有文件,并获取文件生成选项 | |
/// Get all the files in the *.csproj | |
/// </summary> | |
/// <param name="doc">csproj 文件的XDocument</param> | |
/// <returns> | |
/// 文件路径和文件生成选项列表 | |
/// The List that include the file path and it's compile options | |
/// </returns> | |
public static List<PrjFile> GetPrjFile(XDocument doc) | |
{ | |
var projectXml = doc.Root; | |
var name = projectXml.Attribute("xmlns")?.Value;//NameSpace | |
//如果只写 projectXml.Elements("ItemGroup"),结果null | |
//It return null when use projectXml.Elements("ItemGroup") rather than use projectXml.Elements(XName.Get("ItemGroup", name)) | |
//foreach (var file in projectXml.Elements(XName.Get("ItemGroup", name))) | |
//{ | |
// 获取所有的项 | |
// foreach (var temp in file.Elements()) | |
// { | |
// prjFile.Add(new PrjFile() | |
// { | |
// File = temp.Attribute(XName.Get("Include")).Value, | |
// Form = temp.Name.LocalName | |
// }); | |
// } | |
//} | |
return (from file in projectXml.Elements(XName.Get("ItemGroup", name)) | |
from temp in file.Elements() | |
select new PrjFile() | |
{ | |
File = temp.Attribute(XName.Get("Include")).Value, | |
Form = temp.Name.LocalName | |
}).ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment