views:

157

answers:

2

In visual studios i can run code analysis on my .NET project. I am running basic correctness and have 85 warnings. Which is a little much. Also majority of them are in external code.

How do i disable specific warnings so i can focus on the more important warnings? I tried the below but it does not recognize code analysis warnings. (I first tried w/o the CA)

#pragma warning disable CA1820 CA1065 CA2100
+3  A: 

You need to copy a code analysis ruleset and disable the rules you don't like.

Go to the Project Properties, select a ruleset to start from, then click Open.
Uncheck the rules that you don't like, then click Save As.
Finally, select that rule set in Project Properties.

You can also start from scratch, by right-clicking the project or solution and clicking Add New Item, Code Analysis Rule Set.

SLaks
+2  A: 

If you want to disable warnings on a project-wide level:

Go to project properties, the Code Analysis window, and click "Open" next to the rule set to run. Uncheck the warnings you want to ignore, save the ruleset (probably you'll need to do a Save As since you can't modify the default rulesets), go back to the project code analysis tab, and select the ruleset you just saved.

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

Use the SuppressMessageAttribute.

Daniel Plaisted