We’ve been using FxCop for quite some time; it’s an excellent static analysis tool. We also use CodeSmith to generate O/RM business objects and enums from the database. Often FxCop rules that are appropriate to developer code are less applicable to generated code. Since assemblies tend to contain mixes of these code types, we have a problem - how do we eliminate the noise from the FxCop reports?
Rather than turning off a bunch of rules or constantly suppressing violations, we found a better solution today.
Add the attribute
[System.CodeDom.Compiler.GeneratedCode("tool", "version")]
to generated classes.
In a CodeSmith template, this becomes:
[System.CodeDom.Compiler.GeneratedCode("CodeSmith", "<%= CodeSmith.Engine.VersionCheck.GetCurrentVersion() %>")]
Set the FxCop project option to “Suppress analysis results against generated code” (Project / Options / Spelling & Analysis).
I didn’t find this in the FxCop documentation, but see this page for more information.
Update - November 26, 2008
This entry in the Code Analysis Team Blog contains important guidelines for using these attributes.
No Comments/Pingbacks for this post yet...
Development Central is the blog of Bill Sorensen, a professional software developer. Much of this will relate to C#, .NET, and OOP in general.
Disclaimer
These postings are provided "AS IS" with no warranties and confer no rights.