我继承了一些源代码(Visual Studio解决方案和C#项目)并找到了一些项目引用缺少文件的场景。
有没有人知道一个工具会以递归方式解析目录结构,读取每个.csproj项目文件并列出项目文件引用但在磁盘上找不到的任何文件的名称?
答案 0 :(得分:1)
这是一个代码示例,可以满足您的需求:
string path = @"Your Path";
string[] projects = Directory.GetFiles(path, "*.csproj", SearchOption.AllDirectories);
List<string> badRefferences = new List<string>();
foreach (string project in projects)
{
XmlDocument projectXml = new XmlDocument();
projectXml.Load(project);
XmlNodeList hintPathes = projectXml.GetElementsByTagName("HintPath");
foreach (XmlNode hintPath in hintPathes)
{
FileInfo projectFI = new FileInfo(project);
string reference = Path.GetFullPath(Path.Combine(projectFI.DirectoryName, hintPath.InnerText));
if (!File.Exists(reference))
{
badRefferences.Add(reference);
}
}
}
*这只是一个划痕,但它会给你你需要的东西