Question

Is it possible to exclude a complete namespace from all FxCop analysis while still analyzing the rest of the assembly using the SuppressMessageAttribute?

In my current case, I have a bunch of classes generated by LINQ to SQL which cause a lot of FxCop issues, and obviously, I will not modify all of those to match FxCop standards, as a lot of those modifications would be gone if I re-generated the classes.

I know that FxCop has a project option to suppress analysis on generated code, but it does not seem to recognize the entity and context classes created by LINQ 2 SQL as generated code.

Was it helpful?

Solution

If you tag your classes with the [GeneratedCode] attribute, you can use the /ignoregeneratedcode flag with FxCop as described in this MSDN post:

FAQ: How do I prevent FxCop from firing warnings against generated code

You may have to add a new code file and implement new partial classes there to add the attribute to the classes:

[GeneratedCode]
public partial class MainDataContext { }

Just make sure you add everything to the correct namespace when you create your new file.

OTHER TIPS

Add a [GeneratedCode] attribute to the classes.
EDIT: I meant to partial classes with the same names, as explained by the other answer.

Use the Generated Code Attribute, heres the blog post from the Code Analysis team on the subject.

This at the top of the namespace should do the trick:

[GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
<Assembly: SuppressMessage("Microsoft.Design", _
    "CA1020:AvoidNamespacesWithFewTypes", _
    Scope:="namespace", _
    Target:="Missico.IO")> 

Put statement in GlobalSuppressions.vb at root of project.

All I have is VB example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top