How to: Suppress Compiler Warnings
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
You can declutter a build log by specifying one or more kinds of compiler warnings that you don’t want it to contain. For example, you might use this technique to review some but not all of the information that’s generated automatically when you set the build-log verbosity to Normal, Detailed, or Diagnostic. For more information about verbosity, see How to: View, Save, and Configure Build Log Files.
To suppress specific warnings for Visual C# or F#
In Solution Explorer, choose the project in which you want to suppress warnings.
On the menu bar, choose View, Property Pages.
Choose the Build page.
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.
To suppress specific warnings for Visual C++
In Solution Explorer, choose the project or source file in which you want to suppress warnings.
On the menu bar, choose View, Property Pages.
Choose the Configuration Properties category, choose the C/C++ category, and then choose the Advanced page.
Perform one of the following steps:
In the Disable Specific Warnings box, specify the error codes of the warnings that you want to suppress, separated by a semicolon.
In the Disable Specific Warnings box, choose Edit to display more options.
Choose the OK button, and then rebuild the solution.
Suppressing Warnings for Visual Basic
You can hide specific compiler warnings for Visual Basic by editing the .vbproj file for the project. You can also use the Compile Page, Project Designer to suppress warnings by category. For more information, see Configuring Warnings in Visual Basic.
To suppress specific warnings for Visual Basic
In Solution Explorer, choose the project in which you want to suppress warnings.
On the menu bar, choose Project, Unload Project.
In Solution Explorer, open the shortcut menu for the project, and then choose EditProjectName.vbproj.
The project file is opened in the code editor.
Locate the
<NoWarn></NoWarn>
element in the build configuration with which you’re building.The following example shows the
<NoWarn></NoWarn>
element in bold text for the Debug build configuration on an x86 platform:<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PlatformTarget>x86</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineDebug>true</DefineDebug> <DefineTrace>true</DefineTrace> <ErrorReport>prompt</ErrorReport> <NoWarn></NoWarn> <WarningLevel>1</WarningLevel> </PropertyGroup>
Add one or more warning numbers as the value of the
<NoWarn>
element. If you specify multiple warning numbers, separate them with a comma, as the following example shows.<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PlatformTarget>x86</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineDebug>true</DefineDebug> <DefineTrace>true</DefineTrace> <ErrorReport>prompt</ErrorReport> <NoWarn>40059,42024</NoWarn> <WarningLevel>1</WarningLevel> </PropertyGroup>
Save the changes to the .vbproj file.
On the menu bar, choose Project, Reload Project.
On the menu bar, choose Build, Rebuild Solution.
The Output window no longer shows the warnings that you specified.
For more information, see /nowarn.