全局抑制 c# 编译器警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/526443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:47:02  来源:igfitidea点击:

Globally suppress c# compiler warnings

c#compiler-warningssuppress

提问by pondermatic

In my app I have a fair number of entities which have fields which are getting their values set via reflection. (In this case NHibernate is setting them). I'd like to get rid of the "x is never assigned to and will always have its default value 0" warnings, so I can more easily pick out the other warnings. I realize you can surround them in pragma directives, but AFAIK you have to do this for each one. Is there a project wide or solution wide way I could do this?

在我的应用程序中,我有相当多的实体具有通过反射设置其值的字段。(在这种情况下,NHibernate 正在设置它们)。我想摆脱“x 从未分配给并且将始终具有其默认值 0”警告,因此我可以更轻松地挑选出其他警告。我意识到你可以在 pragma 指令中包围它们,但 AFAIK 你必须为每个指令都这样做。是否有项目范围或解决方案范围的方法可以做到这一点?

采纳答案by Autodidact

Use the C# commandline option /nowarn http://msdn.microsoft.com/en-us/library/7f28x9z3(VS.80).aspx

使用 C# 命令行选项 /nowarn http://msdn.microsoft.com/en-us/library/7f28x9z3(VS.80).aspx

To do this within visual studio goto Project properties->Build->(Errors and warnings) Suppress Warningsand then specify a comma separated list of warnings which need to be suppressed.

要在 Visual Studio 中执行此操作,请转到Project properties->Build->(Errors and warnings) Suppress Warnings,然后指定一个逗号分隔的需要抑制的警告列表。

回答by AnthonyWJones

Open the project properties, on the build tab, enter warning IDs you want to surpress in the Suppress warnings: box.

打开项目属性,在 build 选项卡上,在 Suppress warnings: 框中输入要抑制的警告 ID。

回答by Andy Piper

The VC++ XML tag for this is <DisableSpecificWarnings/> with a semi-colon separated list of numeric IDs. This doesn't appear to be documented anywhere that I can see but FYI.

用于此的 VC++ XML 标记是 <DisableSpecificWarnings/> 带有分号分隔的数字 ID 列表。这似乎没有记录在我能看到的任何地方,但仅供参考。