SuppressMessage with FxCop and NON-Team System Visual Studio

If you're using Visual Studio 2005 Team System then FxCop is completely integrated and when you exclude messages it automatically applies the new SuppressMessage attributes to the appropriate location in code. But if you're using Visual Studio Professional edition then you have to use the external FxCop 1.35 UI. If this is the case, you can STILL utilize the SuppressMessage attribute but have to do a couple of things first. I had to do a little digging but the steps are pretty simple.

It turns out you have to enable your project to recognize the SuppressMessage attribute by FIRST adding a condition compilation symbol.

To include this symbol do the following:
C#
1. In Solution Explorer, right-click your project and choose Properties
2. In the Properties window, choose the Build tab
3. In the Conditional compilation symbols text box enter CODE_ANALYSIS

VB
1. In Solution Explorer, right-click your project and choose Properties
2. In the Properties window, choose the Compile tab and click Advanced Compile Options
3. In the Custom constants text box enter CODE_ANALYSIS
Found these steps here:

Now for the cool part. In Team System, you can just right-click on the rule and say "Suppress" and it will automatically add the SuppressMessage attribute in the right spot. In Professional edition, we don't have this integrated into the IDE so we have to use the normal FxCop 1.35 UI (which of course has no knowledge of Visual Studio) – and correctly specifying these attributes is not easy to do by hand. It turns out all you have to do, is to right-click the error message in FxCop UI and select "Copy As" – "SuppressMessage" (or "Module-level SupressMessage"). Then you can simply paste the attribute into your code at the appropriate location. Very slick!

Tweet Post Share Update Email RSS