Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a ruleset from MSBuild

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
like image 960
Thomas Jespersen Avatar asked Jul 05 '10 09:07

Thomas Jespersen


People also ask

How do you write a custom static code analysis rule?

Create a custom rule set from an existing rule setIn Solution Explorer, right-click the project and then select Properties. On the Properties pages, select the Code Analysis tab. In the Active rules drop-down list, do one of the following: Choose the rule set that you want to customize.

What is a rule set in coding?

A rule set is a grouping of code analysis rules that identify targeted issues and specific conditions for that project. For example, you can apply a rule set that's designed to scan code for publicly available APIs. You can also apply a rule set that includes all the available rules.


1 Answers

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
like image 93
Julien Hoarau Avatar answered Sep 18 '22 16:09

Julien Hoarau