views:

57

answers:

1

I have inherited some source code (Visual Studio solutions and C# projects) and have found a couple of scenarios where a project references a file that is missing.

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

+1  A: 

here is a code sample 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);
                }
            }
        }

*This is just a scratch, but it will give you what you need

sagie
I was about to start down this path myself :-)
Richard Ev