Ignore Code Analysis Rules in Visual Studio

How to ignore a specific rule for analyzing VS code (say, CA1305: Microsoft.Globalization) within:

  • Way?
  • Class?
  • Namespace

(Assuming these options are possible).

+6
visual-studio-2008 visual-studio code-analysis
source share
3 answers

I downloaded FXCop as suggested by @True. Comment on @AnthonyWJones answer. This gave me a SuppressMessage message:

[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.String.Format(System.String,System.Object)")] 

It was much harder than it should have been. What happened to this integration of FXCop in Visual Studio? Thanks to the defendants for their help.

+1
source share

You can use the SupressMessage attribute as follows: -

 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "newValue+1", Justification = "The reason I think its acceptable in this case")] void SomeMethod() { // Some code that would normal cause this Code Analysis message } 

About a method, property, type, etc.

+5
source share

Use #pragma warning(suppress: Cxxxx)

You can put the pragma in the appropriate area in the source file (i.e. class, method)

See http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx

+1
source share

All Articles