是否可以禁用特定的编译器警告? [英] Is it possible to disable specific compiler warnings?

查看:132
本文介绍了是否可以禁用特定的编译器警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图禁止特定的编译器警告,即System.Data.OracleClient.OracleConnection' is obsolete.我在这里遇到了这些问题:

I am trying to suppress specific compiler warnings, namely System.Data.OracleClient.OracleConnection' is obsolete. I came upon these questions here:

如何为整个解决方案禁用特定警告?

全局禁止显示c#编译器警告

...但是它们似乎不适用于VS2013.当我转到项目的属性时,没有看到Build选项卡.我看到一个Compile选项卡,但是它似乎没有地方指定要禁止显示的警告消息.我在那里看到一个名为Warning configurations的部分,但没有看到我正在寻找的警告.

...but they don't seem to apply to VS2013. When I go to my project's properties, I don't see a Build tab. I see a Compile tab, but it doesn't appear to have a place to specify warning messages to suppress. I see a section there called Warning configurations, but I don't see the warning I am looking for.

更新:事实证明,我正在尝试针对VB.NET进行此操作.感谢所选答案提供的链接,您必须编辑项目文件的XML,并在<NoWarn></NoWarn>标记中提供警告代码.但是,您必须知道隐藏在错误列表中的警告代码.一种获取方法是打开输出窗口并构建项目.就我而言,警告代码为40000.它显示为BC40000,但是我必须删除BC.重建项目后,警告消息消失了.

Update: It turns out that I am trying to do this for VB.NET. Thanks to a link provided by the selected answer, you have to edit the project file's XML and supply the warning code in the <NoWarn></NoWarn> tag. However, you have to know the warning code which is hidden in the error list. One way to get it is to open the output window and build the project. In my case, the warnign code is 40000. It shows as BC40000, but I had to remove the BC. After rebuilding the project, the warning messages went away.

推荐答案

禁止显示针对Visual C#或F#的特定警告:

To suppress specific warnings for Visual C# or F#:

  1. Solution Explorer 中,选择要在其中隐藏警告的项目.
  2. 在菜单栏上,依次选择查看属性页.
  3. 选择构建页面.
  4. 禁止警告框中,指定要禁止的警告的错误代码,以分号分隔,然后重新构建解决方案.
  1. In Solution Explorer, choose the project in which you want to suppress warnings.
  2. On the menu bar, choose View, Property Pages.
  3. Choose the Build page.
  4. In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons, and then rebuild the solution.

此处中查看有关如何禁止特定警告的更多信息用于Visual C ++和Visual Basic.

Check out here for more info on how to suppress specific warning for Visual C++ and Visual Basic.

另一种方法是使用 #pragma warning 可以启用或禁用某些警告.

Another ways is to use #pragma warning can enable or disable certain warnings.:

#pragma warning disable warning-list
#pragma warning restore warning-list

警告列表

以逗号分隔的警告编号列表.单独输入数字,不要带"CS"前缀. 如果未指定警告编号,则禁用会禁用所有警告,而还原会启用所有警告.

A comma-separated list of warning numbers. Enter the numbers alone, without the "CS" prefix. When no warning numbers are specified, disable disables all warnings and restore enables all warnings.

这篇关于是否可以禁用特定的编译器警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆