Andrew
Andrew

Reputation: 1271

How to suppress specific MSBuild warning

Is there any way to disable specific MSBuild warning (e.g. MSB3253) when running MSBuild from command line? My build script calls msbuild.exe much the following way:

msbuild.exe MySolution.sln /t:Rebuild /p:Configuration=Release

I've found out that I can suppress C# warnings (e.g. CS0618) using another parameter for msbuild.exe:

msbuild.exe MySolution.sln /t:Rebuild /p:Configuration=Release /p:NoWarn=0618

However, this approach doesn't work for MSBuild warnings. Maybe there is another magic property to set?

I'm using .NET 3.5 and VS2008.

Upvotes: 127

Views: 79026

Answers (7)

tm1
tm1

Reputation: 1319

More recent versions of MSBuild support this via command line (as mentioned by EM0) or with properties:

<PropertyGroup>
    <MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3253</MSBuildWarningsAsMessages>
</PropertyGroup>

For details see this comment.

I didn't find official documentation about this, but it is mentioned in the VerifyFileHash task documentation.

Update

The property is now documented as common MSBuild project property.

Upvotes: 18

Konstantin S.
Konstantin S.

Reputation: 1505

Alternative: Add this to .csproj.

<PropertyGroup>
  <NoWarn>$(NoWarn);MSB3253</NoWarn>
</PropertyGroup>
  • You can specify multiple values using ; delimiter
  • It also works for any diagnostic IDs like CS1701 or CA1416
  • $(NoWarn); at the beginning prevents the previous value from being overwritten and instead expands it. This may have been added before this via Directory.Build.props/NuGet/workloads

Upvotes: 18

Caleb Bertrand
Caleb Bertrand

Reputation: 414

At the time of this post (2021), Microsoft docs recommend DisabledWarnings, this worked for me:

<PropertyGroup>
    <DisabledWarnings>3568</DisabledWarnings>
</PropertyGroup>

Note that the "MS" prefix is omitted

Upvotes: -4

Stanislav Berkov
Stanislav Berkov

Reputation: 6287

For MSB3253 you can just set in project file (*.csproj) that cause such warning.

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <!-- some code goes here -->
    <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
        None
    </ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
    <!-- some code goes here -->
  </PropertyGroup>

Upvotes: 48

EM0
EM0

Reputation: 6357

For those Googling this now (like me): the upcoming MSBuild 15.0 (to be released with Visual Studio 2017, I presume) will finally implement the /NoWarn option to suppress specific warnings (as well as /WarnAsError to treat either specific warnings or all warnings as errors).

Upvotes: 14

Yag
Yag

Reputation: 925

I've managed to supress the warning level with /p:WarningLevel=X

msbuild.exe MySolution.sln /t:Rebuild /p:WarningLevel=0 /p:Configuration=Release
                                      ^^^^^^^^^^^^^^^^^
Warning  
Level    Meaning
-------- -------------------------------------------
      0  Turns off emission of all warning messages.

      1  Displays severe warning messages

      2  Displays level 1 warnings plus certain, less-severe warnings, such
         as warnings about hiding class members

      3  Displays level 2 warnings plus certain, less-severe warnings, such 
         as warnings about expressions that always evaluate to true or false

      4  (the default) Displays all level 3 warnings plus informational warnings

Upvotes: 86

Albic
Albic

Reputation: 3629

According to this thread in the MSDN Forum MSBuild warnings can't be suppressed.

Upvotes: 32

Related Questions