Thursday 13 September 2012

Treat Warnings as Errors: Exclude specifics warnings

As every Visual Studio user knows, you should build your project with the "Treat warnings as errors" switched on. This gives you very quick feedback when your project has problems that could otherwise get ignored.

This setting is toggled on the Build tab of the project's properties page:

As it says on the tin, this causes any problem that would normally be reported as a warning to be reported as an error, and prevent the project building:

If there are warnings that you don't want to break your build, you can suppress them specifically. You'll need the warning number, which will be reported in the Output window:

This number, without the CS prefix, needs to be entered in the "Suppress warnings" box, on the Build tab. Multiple warnings can be suppressed, by separating multiple warning codes with a comma.

Victory!

Alternatively, you can use a #pragma compiler directive in the code to suppress your warning:



No comments:

Post a Comment