Disable code analysis warnings.

In visual studios, I can run code analysis in my .NET project. I am doing basic correctness and have 85 warnings. That's not a lot. In addition, most of them are in external code.

How do I disable specific alerts so that I can focus on more important alerts? I tried below but does not recognize code analysis warnings. (I tried without CA first)

#pragma warning disable CA1820 CA1065 CA2100 
+7
visual-studio-2010 code-analysis
source share
2 answers

You need to copy a set of code analysis rules and disable rules that you don't like.

Go to the "Project Properties" section, select the set of rules to run, then click "Open."
Uncheck the rules you don’t like, then click Save As.
Finally, select this rule in the project properties.

You can also start from scratch by right-clicking on a project or solution and clicking Add New Item, Code Analysis Ruleset.

+6
source share

If you want to disable warnings at the project level:

Go to the project properties, the code analysis window and click "Open" next to the set of rules to run. Uncheck the warnings that you want to ignore, save the ruleset (you may need to do “Save as” because you cannot change the default ruleset), go back to the “Project code analysis” tab and select the ruleset which you just saved.

If you just want to disable certain warnings in certain places in the code:

Use SuppressMessageAttribute .

+8
source share

All Articles