Can I Prevent Global Disturbances in FX Cop Code Analysis?

When you use the Visual Studio Code Analyzer (FxCop) and want to suppress the message, there are 3 options.

  • Suppression of violation in the code.
  • Suppression of violation in the GlobalSupression.cs file.
  • Disable violation checking in the project file (via Project β†’ Properties β†’ Code Analysic).

The later version is very difficult to verify when checking on Source Control, and it is difficult to get an overview of all disabled violations. Therefore, we would like to use option 2.

The problem with options 1 and 2 is that you get one line of suppression for each violation. For example, for example:

[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Company.Project.Namespace2")] [assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Company.Project.Namespace1")] 

We would like to do something like this GlobalSuppressions.cs:

 [assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes")] 

But is it possible?

+9
visual-studio code-analysis
Sep 16 '08 at 14:21
source share
2 answers

Suppressing multiple violations with a single SuppressMessage attribute is not officially supported. Apparently this is by design.

I agree, sometimes it can be annoying, but I can’t say that I don’t agree with this decision, because an attribute is their way of making you say, β€œYes, I know what I'm doing,” which should be evaluated on a case-by-case basis.

+9
Sep 16 '08 at 15:07
source share

I think that everything has changed since this question was published and answered. For Visual Studio 2010 and 2012, you can create a custom rule set file in which you can specify which code analysis rules you want to suppress.

http://msdn.microsoft.com/en-us/library/dd380660.aspx

So, I did this to create a single, custom rule-set file, which is located in the top-level folder of my source repository collection, and I reference this file in every Visual Studio project. This means that I have one central place where I can suppress code analysis rules that I simply cannot stand. But if I ever change my mind or decide that I should reconsider my bad coding habits, I can just repeat the rule and see how many code analysis messages I get.

+1
Sep 21 '13 at 9:16
source share



All Articles