Making it easier to move from FxCop to Visual Studio Code Analysis [Jeffrey van Gogh]
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_BASELINE
using System.Diagnostics.CodeAnalysis;
#endif
//////////////////////////////////////////////////////////////////////////////
// Date: Friday, May 19, 2006 1:48:18 PM
// Description: convert FxCop project to in-source
// User: DOMAIN\user
//////////////////////////////////////////////////////////////////////////////
#if
CODE_ANALYSIS_BASELINE
[module: SuppressMessage("Microsoft.Usage", "CA2209:AssembliesShouldDeclareMinimumSecurity", Scope="", Target="demo.dll", MessageId="", Justification="BASELINE: convert FxCop project to in-source")]
[module: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames", Scope="", Target="demo.dll", MessageId="", Justification="BASELINE: convert FxCop project to in-source")]
[module: SuppressMessage("Microsoft.Design", "CA1016:MarkAssembliesWithAssemblyVersion", Scope="", Target="demo.dll", MessageId="", Justification="BASELINE: convert FxCop project to in-source")]
[module: SuppressMessage("Microsoft.Design", "CA1014:MarkAssembliesWithClsCompliant", Scope="", Target="demo.dll", MessageId="", Justification="BASELINE: convert FxCop project to in-source")]
[module: SuppressMessage("Microsoft.Design", "CA1017:MarkAssembliesWithComVisible", Scope="", Target="demo.dll", MessageId="", Justification="BASELINE: convert FxCop project to in-source")]
[module: SuppressMessage("Microsoft.Design", "CA1050:DeclareTypesInNamespaces", Scope="type", Target="demo", MessageId="", Justification="BASELINE: convert FxCop project to in-source, [user]: demo note")]
[module: SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", Scope="type", Target="demo", MessageId="", Justification="BASELINE: convert FxCop project to in-source, [user]: first suppression")]
#endif
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
Comments
Anonymous
May 20, 2006
That sounds pretty cool. I'll have to give it a try.Anonymous
May 20, 2006
Very timely, I'm about to convert some projects to VS2005.
One issue is that I often have a single FxCop project for multiple related assemblies.
It would be nice if a future version of the tool could generate a source file per assembly.Anonymous
May 22, 2006
Rob Caron celebrates the 2nd anniversary of his blog. Some other recent posts: Windows PowerShell script...Anonymous
June 20, 2006
Persone los pioneros non rabata. Great...Anonymous
June 24, 2006
Best of all people w can talk...Anonymous
April 22, 2007
A few months ago, I gave a presentation on using FxCop at the Montreal Visual Studio Users Group . TheAnonymous
November 22, 2007
In previous posts about Code Metrics and Code Reviews , I explored some metrics and techniques that I