MSBuild: Treat single warning as error

后端 未结 2 1024
鱼传尺愫
鱼传尺愫 2021-01-20 03:13

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 deploy

相关标签:
2条回答
  • 2021-01-20 03:52

    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

    0 讨论(0)
  • 2021-01-20 04:06

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

    0 讨论(0)
提交回复
热议问题