diff --git a/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs b/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs index d83d61361fa..e8ead4b2e98 100644 --- a/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs +++ b/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs @@ -417,6 +417,9 @@ public void TaskReturnsFailureButDoesNotLogError_ShouldCauseBuildFailure() } } + /// + /// Test that a task that returns false without logging anything reports MSB4181 as a warning. + /// [Fact] public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_WarnAndContinue() { @@ -439,6 +442,31 @@ public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_WarnAndContinue } } + /// + /// Test that a task that returns false after logging an error->warning does NOT also log MSB4181 + /// + [Fact] + public void TaskReturnsFailureAndLogsError_ContinueOnError_WarnAndContinue() + { + using (TestEnvironment env = TestEnvironment.Create(_output)) + { + TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" + + + + + + + "); + + MockLogger logger = proj.BuildProjectExpectSuccess(); + + // The only warning should be the error->warning logged by the task. + logger.WarningCount.ShouldBe(1); + logger.AssertLogContains("MSB1234"); + } + } + [Fact] public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_True() { diff --git a/src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs b/src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs index 154ace42f96..0c07dae6d6f 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs @@ -455,8 +455,9 @@ public void LogErrorEvent(Microsoft.Build.Framework.BuildErrorEventArgs e) { e.BuildEventContext = _taskLoggingContext.BuildEventContext; _taskLoggingContext.LoggingService.LogBuildEvent(e); - _taskLoggingContext.HasLoggedErrors = true; } + + _taskLoggingContext.HasLoggedErrors = true; } }