简体   繁体   English

如何在 VS2012 中禁用 C# 项目的特定警告?

[英]How can I disable a specific warning for a C# project in VS2012?

I am trying to generate partial XML documentation during my build process for a C# project in VS2012.我正在尝试在 VS2012 中的 C# 项目的构建过程中生成部分 XML 文档。 When I check the XML documentation file option in Project->Properties->Build, I get a build warning for each public member that lacks documentation.当我在 Project->Properties->Build 中检查 XML 文档文件选项时,我收到每个缺少文档的公共成员的构建警告。 Since we compile with warnings as errors, this blocks the build.由于我们将警告作为错误进行编译,因此这会阻止构建。

This question suggests getting past this by disabling certain warnings, but I can't figure out how to do that in VS2012! 这个问题建议通过禁用某些警告来解决这个问题,但我不知道如何在 VS2012 中做到这一点! The MSFT documentation here only goes up to VS2010 and only covers VB. 此处的 MSFT 文档仅适用于 VS2010,并且仅涵盖 VB。 How can I disable these warnings at the project level in C#/VS2012?如何在 C#/VS2012 的项目级别禁用这些警告?

For the project level go to Project -> Properties -> Build tab对于项目级别,转到 Project -> Properties -> Build 选项卡

在此处输入图片说明

If you want to disable the warning to some code section, try this :如果要禁用某些代码部分的警告,请尝试以下操作:

#pragma warning disable XXX,XXX
            //your code 
#pragma warning restore XXX,XXX

Read about #pragma warning阅读#pragma 警告

The warning you're getting has a number (eg CS2000), so what you need to do is right-click on the project, go to the Build tab, and add that warning to the Suppress warnings text box.您收到的警告有一个数字(例如 CS2000),因此您需要做的是右键单击该项目,转到Build选项卡,然后将该警告添加到Suppress warnings文本框中。 You can subsequently suppress more than one by separating them with a comma (eg CS2000,CS2001).随后您可以通过用逗号分隔它们来抑制多个(例如 CS2000,CS2001)。

您可以打开项目属性,然后在“构建”选项卡上的“抑制警告”文本框中输入要抑制的逗号分隔警告编号。

它与 Visual Studio 2010 位于同一位置。在项目属性中,在 Build 选项卡上,称为 Suppress warnings。

Just add NoWarn block in the csproj:只需在 csproj 中添加 NoWarn 块:

<PropertyGroup>
 <NoWarn>1998;1999</NoWarn>
</PropertyGroup>

尝试将 _ALLOW_KEYWORD_MACROS 添加到当前属性页、您的项目、C/C++、预处理器、预处理器定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM