List of file names referenced by projects but does not exist on disk

I inherited some source code (Visual Studio solutions and C # projects) and found several scenarios in which the project refers to a missing file.

Does anyone know a tool that will recursively analyze the directory structure, read each project project .csproj and list the names of any files referenced by the project file, but which cannot be found on disk?

+3
source share
1 answer

here is an example of code that does what you need:

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

* It's just a scratch, but it will give you what you need

+1
source

Source: https://habr.com/ru/post/1729052/


All Articles