Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate .csproj files in solution

I'd like to be able to validate my .csproj files either as they are added to the solution, or when they are built on our CI build server.

Validation would mean checking, for example:

  • that the path and project file name match conventions
  • that the assembly name and namespace match naming conventions
  • that the platform target is correct
  • that the output paths are correct (Release and Debug)
  • that the warnings level is correct and warnings are treated as errors
  • that certain files are present in the project (AssemblyInfo.cs etc).
  • that assemblies have been correctly referenced
  • etc

Another useful feature would be the ability to ignore certain projects, or better still, to be able to define project groupings, with each group having its own validation rules.

This seems to me to be a problem that many others must have, however I have not yet found any tool which could help simplify or automate this process. I'd imagine it to be something like StyleCop or FxCop perhaps.

Does such a tool exist or must I create my own custom build step?

(I am also using ReSharper, so would consider plugins, although this might make validation on the build server more difficult.)

like image 670
g t Avatar asked Jul 21 '15 07:07

g t


1 Answers

AFAIK there's no tool to achieve this. This is the reason why a collague of mine coded an custom tool to validate .csproj and .vbproj files with custom rule validators.

There are some classes to check the project files which might get handy for you like Microsoft.Build.Evaluation.Project (Assembly Microsoft.Build), for example. But it gets quite dirty when you're trying to parse solution files. I highly recommend having a look at this question on StackOverflow.

The inhouse validation tool I'm talking about simply checks for defined rules (like the ToolsVersion, TargetFrameworkVersion, TargetCPU, ...) and plots the corresponding output in a format so that the build server can parse the messages and stop a build if an important rule was broken.

Good luck!

like image 74
Waescher Avatar answered Sep 28 '22 00:09

Waescher