Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild: Treat single warning as error

Is there a way to force MSBuild to treat a certain warning as an error?

When running the Publish target for a ccproj file to make a cspkg for deployment to Azure, this error is thrown:

Project.Name : warning WAT150: The project 'Project.Name' is dependent on the following assembly: C:\Windows\assembly\GAC_64\DllName\2.10.0.0__Guid\DllName.dll. This assembly is not in the package. To make sure that the role starts, add this assembly as a reference to the project and set the Copy Local property to true. [C:\bld\66\797\Sources\Applications\cloud\Project.Name.ccproj]

This is a warning that probably means a role won't start when deployed... I'd like to make WAT150 an error. Is there a way to make a specific, single warning or list of warnings an error?

like image 371
J. Polfer Avatar asked Mar 21 '13 15:03

J. Polfer


2 Answers

In MSBuild you can use the /warnaserror command line switch

  /warnaserror[:code[;code2]]
                     List of warning codes to treats as errors.  Use a semicolon
                     or a comma to separate multiple warning codes. To treat all
                     warnings as errors use the switch with no values.
                     (Short form: /err[:c;[c2]])

                     Example:
                       /warnaserror:MSB4130

                     When a warning is treated as an error the target will
                     continue to execute as if it was a warning but the overall
                     build will fail.

This is equivalent to setting the <WarningsAsErrors> property in the project file (docs).

For completeness, the C# compiler also has the -warnaserror command line option (docs).

like image 107
Drew Noakes Avatar answered Sep 20 '22 14:09

Drew Noakes


in the msbuild commandline options you have this:

warningsAsErrors

Specifies a list of warnings to treat as errors. This parameter is equivalent to the /warnaserror compiler switch.

doc link : http://msdn.microsoft.com/en-us/library/vstudio/bb629394(v=vs.100).aspx

like image 36
smeltplate Avatar answered Sep 19 '22 14:09

smeltplate