Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FxCop and Code Analysis Rules

I recently started using Code Analysis on my projects in Visual Studio. I have created a custom ruleset to use with all of my projects that include two of the Microsoft defined rulesets. I've been working to integrate FxCop into the CI build process to fail builds that don't pass all rules. What's really odd to me is that I can't use my ruleset to define what rules FxCop scans the code against. How do I make it so Visual Studio's Code Analysis rules match up to FxCop's rules?

like image 883
Hungry Beast Avatar asked Mar 27 '12 16:03

Hungry Beast


2 Answers

You already have a rule set file that I assume you have figured out how to integrate in your projects and utilize through Visual Studio.

You can use this same rule set file in FxCopCmd.exe:

FxCopCmd.exe /out:Violations.xml /ruleset:=Custom.ruleset /file:MyAssembly.dll

I have done this using Jenkins and it works just fine. Run FxCopCmd.exe with no arguments and you should see descriptions for all available command-line switches.

like image 65
Bernard Avatar answered Sep 18 '22 00:09

Bernard


For our CI build we have a special build configuration (in addition to standard Debug and Release) which includes running code analysis ("RunCodeAnalysis" MSBuild task as i remember) and option "Treat warning as error". So the build fails if we have an FxCop error and it uses the same rule set as VS. This way you don't need to use FxCopCmd and can share rulesets. But you have to manually add this build configuration to every project of your solution.

like image 32
Nikolay Avatar answered Sep 22 '22 00:09

Nikolay