Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude complete namespace from FxCop code analysis?

Tags:

fxcop

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.

like image 956
hangy Avatar asked Dec 09 '08 15:12

hangy


4 Answers

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.

like image 152
Justin Niessner Avatar answered Nov 10 '22 09:11

Justin Niessner


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

like image 5
SLaks Avatar answered Nov 10 '22 09:11

SLaks


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")]
like image 1
Chane Avatar answered Nov 10 '22 10:11

Chane


<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.

like image 1
AMissico Avatar answered Nov 10 '22 09:11

AMissico