.net – FxCop and Code Analysis Rules

code analysisfxcopnetteamcityvisual studio

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?

Best Answer

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.