We get frequently asked what the best way is for people to move from the standalone FxCop to VS Code Analysis. A hurdle in making the switch is the fact that people can no longer use the FxCop project file they created for their analysis. This will invalidate all the exclusions that were made previously and stored in the FxCop project file.
Another frequently reported question is how to create an in-source baseline for projects that currently have huge amount of FxCop violations, to stop the bleeding of new violations coming online without having to stop to become 100% clean.
Until now we didn’t have a way of easily mitigating both issues. Based on the feedback we’ve received, we decided to write a power tool that will make it possible to move existing exclusions over to in source suppressions.
The tool is a simple command line script that will transform any .FxCop or .CodeAnalysisReport.xml file into a source file containing assembly level suppressions (also known as global suppressions).
The syntax for running the command is as follows:
Usage: Baseline /language <C#|VB|C++> /report <code analysis report> /output <output file> /description description
When converting from FxCop standalone to in-source, pass the .FxCop file to the tool. When creating a baseline for a project in Visual Studio, first run Code Analysis the usual way, then locate the .CodeAnalysisReport.xml file in the output directory of your project and pass that to the tool.
A run like:
Baseline /language C# /report demo.fxcop /output demo.cs /description “convert FxCop project to in-source”
Will give a source file like this:
#if CODE_ANALYSIS_BASELINEusing System.Diagnostics.CodeAnalysis;#endif
//////////////////////////////////////////////////////////////////////////////// Date: Friday, May 19, 2006 1:48:18 PM// Description: convert FxCop project to in-source// User: DOMAIN\user//////////////////////////////////////////////////////////////////////////////
The next step is to add this generated source file to the Visual Studio project and add the CODE_ANALYSIS_BASELINE define to the list of compiler defines.
Now Code Analysis functionality inside Visual Studio will pickup the newly created assembly level suppressions. When it is time to attack the baseline, the only thing that needs to be done is to remove CODE_ANALYSIS_BASELINE from the list of defines to get the analysis results to show up again.
I’ve attached the baseline tool to this blog post. Please let us know what you think of it by posting comments & bug reports on the FxCop forum