Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for "warning as errors except ..." #3062

Closed
natemcmaster opened this issue Mar 7, 2018 · 13 comments · Fixed by #7309
Closed

Add option for "warning as errors except ..." #3062

natemcmaster opened this issue Mar 7, 2018 · 13 comments · Fixed by #7309
Assignees
Milestone

Comments

@natemcmaster
Copy link
Contributor

Follow up to #68

I would like to have the ability to make all warnings by errors, but with some exclusions.

msbuild.exe -warnAsError -warnNotAsError MSB3277

This is not the same as -nowarn which would make the warning a low-importance message and hide the warning. I still want the warnings to appear as warnings so show the user there may be a problem, but I want to be able to specify which problems are non-fatal.

My scenario:
We would like to enable -warnAsError by default in the build system that produces ASP.NET Core, but we can't because there are a handful of warning that we can't always do anything about. We would like the warnings to appear, but to be non-fatal to a build passing.

For comparison, C# supports a WarningsNotAsErrors properties which allows users to set TreatWarningsAsErrors=true which exclusions defined as WarningsNotAsErrors.

@ghost
Copy link

ghost commented Mar 16, 2018

Just sent a PR for inclusion in F# project system request as well dotnet/fsharp#3395 😄

@MarkKharitonov
Copy link

MarkKharitonov commented Nov 19, 2018

I need that too.
We do not even need a new flag. There is already the /nowarn flag, just assign it higher priority than /err.

@rainersigwald
Copy link
Member

@MarkKharitonov That is already the case. This is a request to make some warnings produced as warnings even when -warnAsError is set.

$ type warnaserror.proj
<Project>
 <Target Name="Warn">
  <Warning Code="Code1" Text="Warning 1" />
  <Warning Code="Code2" Text="Warning 2" />
 </Target>
</Project>

$ msbuild warnaserror.proj -warnAsError
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/19/2018 10:02:37 AM.
Project "s:\warnaserror.proj" on node 1 (default targets).
s:\warnaserror.proj(3,3): error Code1: Warning 1
s:\warnaserror.proj(4,3): error Code2: Warning 2
Done Building Project "s:\warnaserror.proj" (default targets).


Build FAILED.

"s:\warnaserror.proj" (default target) (1) ->
(Warn target) ->
  s:\warnaserror.proj(3,3): error Code1: Warning 1


"s:\warnaserror.proj" (default target) (1) ->
  s:\warnaserror.proj(4,3): error Code2: Warning 2

    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:00.10

$ msbuild warnaserror.proj -warnAsError -nowarn:Code1
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/19/2018 10:02:47 AM.
Project "s:\warnaserror.proj" on node 1 (default targets).
s:\warnaserror.proj(4,3): error Code2: Warning 2
Done Building Project "s:\warnaserror.proj" (default targets).


Build FAILED.

"s:\warnaserror.proj" (default target) (1) ->
(Warn target) ->
  s:\warnaserror.proj(4,3): error Code2: Warning 2

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.12

$ msbuild warnaserror.proj -warnAsError -nowarn:Code1 -verbosity:detailed
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/19/2018 10:03:03 AM.
Project "s:\warnaserror.proj" on node 1 (default targets).
Building with tools version "15.0".
Target "Warn" in project "s:\warnaserror.proj" (entry point):
Using "Warning" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5
f7f11d50a3a".
Task "Warning"
s:\warnaserror.proj(3,3): message Code1: Warning 1
Done executing task "Warning".
Task "Warning"
s:\warnaserror.proj(4,3): error Code2: Warning 2
Done executing task "Warning".
Done building target "Warn" in project "warnaserror.proj".
Done Building Project "s:\warnaserror.proj" (default targets).


Build FAILED.

"s:\warnaserror.proj" (default target) (1) ->
(Warn target) ->
  s:\warnaserror.proj(4,3): error Code2: Warning 2

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.18

@MarkKharitonov
Copy link

MarkKharitonov commented Nov 19, 2018

Excellent, then we do not have a problem. So, I can pass /err /nowarn:MSB3026 to treat all the warnings as errors except for MSB3026

I do not know if this is your thing, but could you answer to https://stackoverflow.com/questions/53375076/does-the-new-msbuild-15-warnaserror-switch-allow-to-fail-on-all-the-warnings-ex?noredirect=1#comment93638635_53375076 so that I could credit you?

@sandyarmstrong
Copy link
Member

This would be very useful, so that build output still shows the warnings, but simply doesn't treat them as errors.

@benvillalobos benvillalobos self-assigned this Feb 26, 2021
@benvillalobos
Copy link
Member

Is there still demand for a feature like this despite the workaround @rainersigwald suggested further up in this thread? msbuild warnaserror.proj -warnAsError -nowarn:Code1

@benvillalobos benvillalobos added this to the Backlog milestone May 21, 2021
@benvillalobos benvillalobos removed their assignment May 21, 2021
@benvillalobos
Copy link
Member

Linking some relevant pull requests:

#6174

#6308

#5774

@leshy84
Copy link

leshy84 commented Jun 17, 2021

We also bumped into the problem in C# projects:

<PropertyGroup>
  <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  <WarningsNotAsErrors>NU1701</WarningsNotAsErrors>
</PropertyGroup>

We expected the warning to be displayed as warning, but it's displayed as error.
So had to replace WarningsNotAsErrors with NoWarn property to hide the warning completely.

@rseanhall
Copy link

Yes, I would still like this feature. So would the people commenting on #5053.

@benvillalobos benvillalobos modified the milestones: Backlog, VS 17.2 Jan 11, 2022
@benvillalobos
Copy link
Member

Will make sure we at least discuss this during our next planning meeting.

@Forgind Forgind self-assigned this Jan 20, 2022
Forgind added a commit to Forgind/msbuild that referenced this issue Jan 21, 2022
Forgind added a commit that referenced this issue Feb 16, 2022
Fixes #3062

Context
We previously had warnaserror (and a property for it) that, when you specified error codes, upgraded those error codes from warnings to errors. If you just left it empty, it upgraded all warnings to errors. (Null meant don't upgrade.)

This adds that you can ask for all error codes to be upgraded, then downgrade just a few of them (via codes) back to warnings.

Changes Made
Implement WarnNotAsError both as a command line switch and as a property.

Testing
Added a unit test. Tried it out from the command line.
@rseanhall
Copy link

Thanks!

@baronfel
Copy link
Member

Added the Documentation label to signal that we need a Docs addition for this feature.

@Forgind
Copy link
Member

Forgind commented Feb 23, 2022

@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants