Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding Code Analysis rule in source

In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels.

I'd like to suppress those methods in source, so I copied the suppression code generated by FxCop into AssemblyInfo.cs, but it doesn't work.

This is the attribute that FxCop copied to the clipboard.

[module: SuppressMessage("Microsoft.Globalization",
    "CA1303:DoNotPassLiteralsAsLocalizedParameters",
    Scope = "member",
    Target = "WindowsClient.MainForm.InitializeComponent():System.Void",
    MessageId = "System.Windows.Forms.Control.set_Text(System.String)")]

Anyone knows the correct attribute to suppress this messages?

PS: I'm using Visual Studio 2005, C#, FxCop 1.36 beta.

like image 981
Julio César Avatar asked Aug 30 '08 01:08

Julio César


People also ask

How do I turn off Code Analysis?

To open this page, right-click the project node in Solution Explorer and select Properties. Select the Code Analysis tab. To disable source analysis at build time, uncheck the Run on build option. To disable live source analysis, uncheck the Run on live analysis option.

How do I ignore errors in Visual Studio?

Suppress specific warnings for Visual C# or F# Or, select the project node and press Alt+Enter. Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.

How do I disable Fxcop?

Right click on your project node in Solution Explorer, choose Properties. There is a Code Analysis tab near the bottom. Click that and uncheck "Enable Code Analysis on Build".


2 Answers

You've probably got the right code, but you also need to add CODE_ANALYSIS as a precompiler defined symbol in the project properties. I think those SuppressMessage attributes are only left in the compiled binaries if CODE_ANALYSIS is defined.

like image 128
Matt Hamilton Avatar answered Sep 17 '22 21:09

Matt Hamilton


In FxCop 1.36 there is actually a project option on the "Spelling & Analysis" tab that will supress analysis for any generated code.

If you don't want to turn analysis off for all generated code, you need to make sure that you add a CODE_ANALYSIS symbol to the list of conditional compilation symbols (project properties, Build tab). Without this symbol defined, the SupressMessage attributes will be removed from the compiled code so FxCop won't see them.

The other problem with your SuppressMessage attribute is that you are listing a "Target" of a specific method name (in this case WindowsClient.MainForm.InitializeComponent():System.Void) and listing a specific "Scope". You may want to try removing these; otherwise you should add this SuppressMessage to each instance of the method.

You should also upgrade to the RTM version of FxCop 1.36, the beta will not automatically detect the newer version.

like image 41
Scott Dorman Avatar answered Sep 18 '22 21:09

Scott Dorman