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

HasLoggedErrors should respect MSBuildWarningsAsErrors #5511

Closed
sbomer opened this issue Jul 13, 2020 · 1 comment · Fixed by #6174
Closed

HasLoggedErrors should respect MSBuildWarningsAsErrors #5511

sbomer opened this issue Jul 13, 2020 · 1 comment · Fixed by #6174
Assignees
Labels
Area: Engine Issues impacting the core execution of targets and tasks. changewave16.10 Partner request triaged

Comments

@sbomer
Copy link
Member

sbomer commented Jul 13, 2020

Steps to reproduce

warnaserr.tar.gz

    public class MyTask : Task
    {
        public override bool Execute()
        {
            Log.LogWarning(subcategory: null,
                           warningCode: "MyWarning1234",
                           helpKeyword: null,
                           file: null,
                           lineNumber: 0,
                           columnNumber: 0,
                           endLineNumber: 0,
                           endColumnNumber: 0,
                           message: "my warning");

            return !Log.HasLoggedErrors;
        }
    }
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <MSBuildWarningsAsErrors>MyWarning1234</MSBuildWarningsAsErrors>
  </PropertyGroup>

  <UsingTask TaskName="task.MyTask" AssemblyFile="$(MSBuildThisFileDirectory)../task/bin/Debug/net5.0/task.dll" />
  <Target Name="MyTargetOuter"
          DependsOnTargets="MyTargetInner">
    <Message Importance="High" Text="Outer target" />
  </Target>

  <Target Name="MyTargetInner">
    <MyTask />
  </Target>
> dotnet msbuild /t:MyTargetOuter
warnaserr/project/project.csproj(16,5): error MyWarning1234: my warning
  Outer target

Expected behavior

Log.HasLoggedErrors returns true when the logged warning is treated as an error due to MSBuildWarningsAsErrors, causing the build to stop after MyTask.

Actual behavior

HasLoggedErrors returns false, the build continues, and the outer target runs even after the task produced an error.

Perhaps this is the intended behavior. If that's the case, is there a recommended way for tasks to check whether any of their warnings have been turned into errors?

We are using ToolTask (which relies on HasLoggedErrors by default) for the IL linker MSBuild task, and we don't want to continue the build if any errors were logged - otherwise we touch a file on disk that prevents the linker from running incrementally next time.

Environment data

msbuild /version output: 16.7.0.36003

OS info: 18.04.1-Ubuntu

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc): dotnet cli

@rainersigwald
Copy link
Member

Team triage: we think that it's right that this is how it should behave.

We're a bit concerned about two scenarios:

  • User has a project that warns-as-errors, builds it, and expects output (even though it would fail today).
  • User expects errors from downstream targets that would now be dropped.

We think this should be fixed to match your expectations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment