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
Steps to reproduce
warnaserr.tar.gz
Expected behavior
Log.HasLoggedErrorsreturnstruewhen the logged warning is treated as an error due toMSBuildWarningsAsErrors, causing the build to stop afterMyTask.Actual behavior
HasLoggedErrorsreturnsfalse, 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
HasLoggedErrorsby 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 /versionoutput: 16.7.0.36003OS info: 18.04.1-Ubuntu
If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc): dotnet cli