Reputation: 1637
I'm looking for a way to check if all projects in solution have references from "right" path.
Let's say, that references can by only:
any other path is not allowed.
I would like to have this validation during build on TFS or (and) as a check-in rule. Is there a way how to do it?
I would probably be able to write Visual Studio extension an dig into EnvDTE object. But this is backup plan.
Upvotes: 2
Views: 105
Reputation: 10090
Directory.GetFiles(ROOTPATH, "*.csproj", SearchOption.AllDirectories);
Search the .CSPROJ file using XPATH query to find the HintPath nodes:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(nameofcsprojfile);
//Find the current namespace from the XMLDOC and add it to XMLNMManager
XmlNamespaceManager xnManager = new XmlNamespaceManager(xmlDoc.NameTable);
xnManager.AddNamespace("nm", xmlDoc.DocumentElement.NamespaceURI);
//find the nodes based on the following XPATH query
XmlNode xmlRoot = xmlDoc.DocumentElement;
XmlNodeList xmlProperty = xmlRoot.SelectNodes("//nm:ItemGroup/Reference[@Include]", xnManager);
Go through each of the Reference node and get the HintPath property and make sure that it contain (lib or lib2).
If it does not contain, then error out the activity. You can write the following code within the activity to error out the build.
context.TrackBuildError("fix the reference issues!!!");
Upvotes: 1
Reputation: 22245
I'm not aware of a way to enforce this via static analysis (which seems to be what you want).
However, by having a CI build setup it achieves the same thing in practice. If people reference things in \bin\debug (which is the typical problem), the CI build won't find them as it directs the binaries to a different directory, the CI Build will fail, and developers will be forced to use proper references to lib.
Upvotes: 1