Skip to content

Commit d0cb70a

Browse files
authored
Allow MSBuildWarningsAsMessages with comma separation (#11522)
Fixes #7094 Context We don't support NAT011,NAT012, when warnings with comma separation, the Warings are not suppressed. Changes Made Parse warning codes with comma separation and semicolon Testing MSBuildWarningsAsMessagesWithCommaSeparation()
1 parent d047377 commit d0cb70a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs

+28
Original file line numberDiff line numberDiff line change
@@ -527,5 +527,33 @@ public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_False()
527527
logger.AssertLogContains("MSB4181");
528528
}
529529
}
530+
531+
/// <summary>
532+
/// MSBuildWarningsAsMessages should allow comma separation.
533+
/// </summary>
534+
[Fact]
535+
public void MSBuildWarningsAsMessagesWithCommaSeparation()
536+
{
537+
using (TestEnvironment env = TestEnvironment.Create(_output))
538+
{
539+
var content = """
540+
<Project>
541+
<PropertyGroup>
542+
<MSBuildWarningsAsMessages>NAT011,NAT012</MSBuildWarningsAsMessages>
543+
</PropertyGroup>
544+
545+
<Target Name='Build'>
546+
<Warning Code="NAT011" Text="You fail" />
547+
<Warning Code="NAT012" Text="Other Fail" />
548+
</Target>
549+
</Project>
550+
""";
551+
TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles(content);
552+
553+
MockLogger logger = proj.BuildProjectExpectSuccess();
554+
logger.WarningCount.ShouldBe(0);
555+
logger.ErrorCount.ShouldBe(0);
556+
}
557+
}
530558
}
531559
}

src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,9 @@ private static ISet<string> ParseWarningCodes(string warnings)
15201520
return null;
15211521
}
15221522

1523-
return new HashSet<string>(ExpressionShredder.SplitSemiColonSeparatedList(warnings), StringComparer.OrdinalIgnoreCase);
1523+
return new HashSet<string>(ExpressionShredder.SplitSemiColonSeparatedList(warnings)
1524+
.SelectMany(w => w.Split([','], StringSplitOptions.RemoveEmptyEntries))
1525+
.Select(w => w.Trim()), StringComparer.OrdinalIgnoreCase);
15241526
}
15251527

15261528
private sealed class DedicatedThreadsTaskScheduler : TaskScheduler

0 commit comments

Comments
 (0)