So one of the new features I've found with Static Code Analysis in Visual Studio 2005 is that it allows you to suppress messages. As I blogged earlier, the typical behavior is for the tool to add a line to your source file to suppress a warning that you find to be unnecessary. So I was playing with the Namespace related rules which allow you to try and keep variables named appropriately and it flagged the namespace name I used. I have an acronym as my Namespace and that meant it’s all capitals which of course the rule didn’t like. So I decided to ignore the warning, only this time since the warning occurs across several files instead of adding a line to each file which referenced the namespace the Static Analysis tool created a new source file called GlobalSuppressions.cs and added the suppression line to that file. Here are the contents of this new source file in my project:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1705:LongAcronymsShouldBePascalCased", Scope = "namespace", Target = "IKRulz")]
As you can see the only thing in the file is the declaration to create an exception for that rule, but in theory I could add other rules to this file if I found the same message in several locations in my code allowing me to limit the number of times I needed to exclude a particular message. Of course I could also just avoid running certain rules, but that’s a different discussion.