Skip to content

Commit

Permalink
Logger emits message on invalid property name (#9570)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maridematte authored Jan 4, 2024
1 parent bbe185f commit abb49cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Build/Definition/ProjectCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1732,6 +1733,7 @@ private void ShutDownLoggingService()
{
try
{
(LoggingService as LoggingService)?.WaitForLoggingToProcessEvents();
((IBuildComponent)LoggingService).ShutdownComponent();
}
catch (LoggerException)
Expand Down
16 changes: 16 additions & 0 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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", @"
<Project>
<Target Name=""Build"">
</Target>
</Project>
");
string results = RunnerUtilities.ExecMSBuild($" {project.Path} /p:someProperty:fdalse= ", out bool success);
success.ShouldBeFalse(results);

results.ShouldContain("error MSB4177");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down

0 comments on commit abb49cf

Please sign in to comment.