Visual-studio – 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",
    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.

Best Solution

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.