开发者

Disable Code analysis warnings .NET

开发者 https://www.devze.com 2022-12-31 02:19 出处:网络
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.

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 开发者_Go百科CA2100


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消