Suppressing FxCop warnings for generated code

11/13/08

Permalink 10:28:05 pm, by truewill Email , 166 words, 55 views   English (US)
Categories: Tips, C#, Quality, .NET, Tools

Suppressing FxCop warnings for generated code

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.

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))
The name truewill is composed of two other words. What is the SECOND word?

Development Central

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.

Search

Categories

Linkblog

b2evolution

contributors

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 2

powered by b2evolution free blog software