How do I specify a ruleset from MSBuild

Thomas Jespersen picture Thomas Jespersen · Jul 5, 2010 · Viewed 8.9k times · Source

After upgrading to VS 2010 MSBUILD /p:RunCodeAnalysis=true does not work as expected

msbuild solution.sln /p:RunCodeAnalysis=true

To get faster builds we removed the CODE_ANALYSIS constant for the DEBUG build. But that means thet when running the above msbuild command, it defauls to all rules, instead of using the ruleset we specified in on the "Code Analysis" tab on the project property page.

So now I need to build in release mode to run code analasis (which has the CODE_ANALYSIS constant defined):

msbuild solution.sln /p:RunCodeAnalysis=true /p:Configuration=release

This however means we get a release build on our dev machines. And this has some side effects in our setup.

Question: How do I specify the rulset from a command line. I was hoping something like:

msbuild solution.sln /p:RunCodeAnalysis=true /p:foobar=rules.ruleset

Answer

Julien Hoarau picture Julien Hoarau · Jul 5, 2010

You'll have to use the CodeAnalysisRuleSet property.

msbuild solution.sln /p:RunCodeAnalysis=true;CodeAnalysisRuleSet=GlobalizationRules.ruleset

Here is the predefined ruleset list :

  • AllRules.ruleset
  • BasicCorrectnessRules.ruleset
  • BasicDesignGuidelineRules.ruleset
  • ExtendedCorrectnessRules.ruleset
  • ExtendedDesignGuidelineRules.ruleset
  • GlobalizationRules.ruleset
  • MinimumRecommendedRules.ruleset
  • SecurityRules.ruleset