From abb49cf8d7aab276fc6cbd59afd07197485592de Mon Sep 17 00:00:00 2001 From: Mariana Dematte Date: Thu, 4 Jan 2024 14:16:52 +0100 Subject: [PATCH] Logger emits message on invalid property name (#9570) Fixes #9475 Context When a property name is an invalid input, we log the error and shutdown the loggers when terminating the process. However, we did not flush the logs of any messages being processed before shutting down, making we miss this specific error in the process. Changes Made Added a wait for loggers to finish doing their work before shutting down. Testing Added a test to make sure that the logger emits the message before shutdown. --- src/Build/Definition/ProjectCollection.cs | 2 ++ src/MSBuild.UnitTests/XMake_Tests.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index 924b3e25db7..11dd0a1143d 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Xml; using Microsoft.Build.BackEnd; +using Microsoft.Build.BackEnd.Logging; using Microsoft.Build.Collections; using Microsoft.Build.Construction; using Microsoft.Build.Execution; @@ -1732,6 +1733,7 @@ private void ShutDownLoggingService() { try { + (LoggingService as LoggingService)?.WaitForLoggingToProcessEvents(); ((IBuildComponent)LoggingService).ShutdownComponent(); } catch (LoggerException) diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs index c18c5ad2d90..33c482df035 100644 --- a/src/MSBuild.UnitTests/XMake_Tests.cs +++ b/src/MSBuild.UnitTests/XMake_Tests.cs @@ -793,6 +793,22 @@ public void ExecuteAppWithGetPropertyItemAndTargetResult( results.ShouldNotContain(ResourceUtilities.GetResourceString("BuildFailedWithPropertiesItemsOrTargetResultsRequested")); } + [Fact] + public void BuildFailsWithBadPropertyName() + { + using TestEnvironment env = TestEnvironment.Create(); + TransientTestFile project = env.CreateFile("testProject.csproj", @" + + + + +"); + string results = RunnerUtilities.ExecMSBuild($" {project.Path} /p:someProperty:fdalse= ", out bool success); + success.ShouldBeFalse(results); + + results.ShouldContain("error MSB4177"); + } + [Theory] [InlineData(true)] [InlineData(false)]