Domanda

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

How to disable specific warnings for the entire solution?

Globally suppress c# compiler warnings

...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.

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.

È stato utile?

Soluzione

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

  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.

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


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

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

warning-list

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.

Altri suggerimenti

Yes, it is possible.

#pragma warning disable 'warning-number-list'

where warning-number-list is a comma separated list of warning numbers to disable, e.g. 1004

This will disable the warning from its point of declaration to the end of the current file unless re-enable with:

#pragma warning restore 'warning-number-list'.

These pragmas are placed inline in your code at the site of where you wish to disable/restore the warnings.

I believe there is also a place on the Project properties tabs to specify warnings to disable, as you mentioned.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top