2010-01-19 56 views
3

我已经继承了一些源代码(Visual Studio解决方案和C#项目),并找到了一些项目引用缺少文件的情况。项目引用但磁盘上不存在的文件的列表名称

有谁知道一个会递归解析目录结构的工具,读取每个.csproj项目文件并列出项目文件引用的但在磁盘上找不到的任何文件的名称?

回答

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); 
       } 
      } 
     } 

*这仅仅是一个从无到有,但它会给你你需要

+0

我正要开始沿着这条路自己是什么: - ) – 2010-01-19 12:29:17

相关问题