From 72a65cdcd932c38cb882fe3c5b1df961d4927932 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:53:43 +0000 Subject: [PATCH 1/5] Initial plan From 56ebab64f1614d923e9ecf69f02b082f554fa850 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:05:36 +0000 Subject: [PATCH 2/5] Fix ShouldTreatWarningAsError checking wrong collection in OOP TaskHost, gated behind ChangeWave 18.6 Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/03b30797-b232-48c5-a710-7361a11ff69d --- documentation/wiki/ChangeWaves.md | 1 + .../OutOfProcTaskHostNode_Tests.cs | 182 ++++++++++++++++++ src/MSBuild/OutOfProcTaskHostNode.cs | 7 + 3 files changed, 190 insertions(+) create mode 100644 src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index 68cae7eb843..20857ed4c70 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -31,6 +31,7 @@ Change wave checks around features will be removed in the release that accompani ### 18.6 - [AbsolutePath.GetCanonicalForm optimization - avoid expensive Path.GetFullPath calls when paths don't need canonicalization](https://github.com/dotnet/msbuild/pull/13369) +- [Fix ShouldTreatWarningAsError in OOP TaskHost checking wrong collection (WarningsAsMessages instead of WarningsAsErrors)](https://github.com/dotnet/msbuild/issues/11952) ### 18.5 - [FindUnderPath and AssignTargetPath tasks no longer throw on invalid path characters when using TaskEnvironment.GetAbsolutePath](https://github.com/dotnet/msbuild/pull/13069) diff --git a/src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs b/src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs new file mode 100644 index 00000000000..fc9fcfb5023 --- /dev/null +++ b/src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs @@ -0,0 +1,182 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using Microsoft.Build.CommandLine; +using Microsoft.Build.Framework; +using Microsoft.Build.Shared; +using Microsoft.Build.UnitTests; +using Shouldly; +using Xunit; +using Xunit.Abstractions; + +#nullable disable + +namespace Microsoft.Build.CommandLine.UnitTests +{ + public sealed class OutOfProcTaskHostNode_Tests + { + private readonly ITestOutputHelper _output; + + public OutOfProcTaskHostNode_Tests(ITestOutputHelper output) + { + _output = output; + } + + [Fact] + public void ShouldTreatWarningAsError_SpecificCode_ReturnsTrue() + { + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet { "MY0001" }); + SetWarningsAsMessages(node, null); + SetWarningsNotAsErrors(node, null); + + node.ShouldTreatWarningAsError("MY0001").ShouldBeTrue(); + } + + [Fact] + public void ShouldTreatWarningAsError_SpecificCode_OtherCode_ReturnsFalse() + { + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet { "MY0001" }); + SetWarningsAsMessages(node, null); + SetWarningsNotAsErrors(node, null); + + node.ShouldTreatWarningAsError("OTHER0001").ShouldBeFalse(); + } + + [Fact] + public void ShouldTreatWarningAsError_TreatAll_ReturnsTrue() + { + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet()); + SetWarningsAsMessages(node, null); + SetWarningsNotAsErrors(node, null); + + node.ShouldTreatWarningAsError("ANY0001").ShouldBeTrue(); + } + + [Fact] + public void ShouldTreatWarningAsError_TreatAll_OverriddenByNotAsErrors_ReturnsFalse() + { + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet()); + SetWarningsAsMessages(node, null); + SetWarningsNotAsErrors(node, new HashSet { "MY0001" }); + + node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); + } + + [Fact] + public void ShouldTreatWarningAsError_Null_ReturnsFalse() + { + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, null); + SetWarningsAsMessages(node, null); + SetWarningsNotAsErrors(node, null); + + node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); + } + + [Fact] + public void ShouldTreatWarningAsError_WarningAsMessage_ReturnsFalse() + { + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet { "MY0001" }); + SetWarningsAsMessages(node, new HashSet { "MY0001" }); + SetWarningsNotAsErrors(node, null); + + // WarningsAsMessages overrides WarningsAsErrors + node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); + } + + [Fact] + public void ShouldTreatWarningAsError_SpecificCode_NullWarningsAsMessages_ReturnsTrue() + { + // This is the exact scenario from the bug report: + // WarningsAsErrors = {"MY0001"}, WarningsAsMessages = null + // The old buggy code would NRE on WarningsAsMessages.Contains(). + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet { "MY0001" }); + SetWarningsAsMessages(node, null); + SetWarningsNotAsErrors(node, null); + + node.ShouldTreatWarningAsError("MY0001").ShouldBeTrue(); + } + + [Fact] + public void ShouldTreatWarningAsError_SpecificCode_ChangeWaveDisabled_PreservesOldBehavior() + { + // When ChangeWave 18.6 is disabled, the old buggy behavior is preserved. + using TestEnvironment env = TestEnvironment.Create(_output); + ChangeWaves.ResetStateForTests(); + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave18_6.ToString()); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + + OutOfProcTaskHostNode node = new(); + SetWarningsAsErrors(node, new HashSet { "MY0001" }); + SetWarningsAsMessages(node, new HashSet()); + SetWarningsNotAsErrors(node, null); + + // With old behavior, WarningsAsMessages.Contains("MY0001") is checked instead of WarningsAsErrors, + // so this returns false (bug). + node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); + } + + private static void SetWarningsAsErrors(OutOfProcTaskHostNode node, ICollection value) + { + typeof(OutOfProcTaskHostNode) + .GetProperty("WarningsAsErrors", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) + .SetValue(node, value); + } + + private static void SetWarningsAsMessages(OutOfProcTaskHostNode node, ICollection value) + { + typeof(OutOfProcTaskHostNode) + .GetProperty("WarningsAsMessages", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) + .SetValue(node, value); + } + + private static void SetWarningsNotAsErrors(OutOfProcTaskHostNode node, ICollection value) + { + typeof(OutOfProcTaskHostNode) + .GetProperty("WarningsNotAsErrors", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) + .SetValue(node, value); + } + } +} diff --git a/src/MSBuild/OutOfProcTaskHostNode.cs b/src/MSBuild/OutOfProcTaskHostNode.cs index f8dfcd6c8ce..db0a6172e2c 100644 --- a/src/MSBuild/OutOfProcTaskHostNode.cs +++ b/src/MSBuild/OutOfProcTaskHostNode.cs @@ -335,6 +335,13 @@ public bool ShouldTreatWarningAsError(string warningCode) return false; } + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave18_6)) + { + // An empty set means all warnings are errors. + return (WarningsAsErrors.Count == 0 && WarningAsErrorNotOverriden(warningCode)) || WarningsAsErrors.Contains(warningCode); + } + + // Pre-18.6 buggy behavior: checked WarningsAsMessages instead of WarningsAsErrors. return (WarningsAsErrors.Count == 0 && WarningAsErrorNotOverriden(warningCode)) || WarningsAsMessages.Contains(warningCode); } From 89849103cc360d4ae9708ed36efe534f68b1c476 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:06:48 +0000 Subject: [PATCH 3/5] Improve backward compatibility comment per code review Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/03b30797-b232-48c5-a710-7361a11ff69d --- src/MSBuild/OutOfProcTaskHostNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuild/OutOfProcTaskHostNode.cs b/src/MSBuild/OutOfProcTaskHostNode.cs index db0a6172e2c..112fa08024a 100644 --- a/src/MSBuild/OutOfProcTaskHostNode.cs +++ b/src/MSBuild/OutOfProcTaskHostNode.cs @@ -341,7 +341,7 @@ public bool ShouldTreatWarningAsError(string warningCode) return (WarningsAsErrors.Count == 0 && WarningAsErrorNotOverriden(warningCode)) || WarningsAsErrors.Contains(warningCode); } - // Pre-18.6 buggy behavior: checked WarningsAsMessages instead of WarningsAsErrors. + // Pre-18.6 behavior preserved for backward compatibility: incorrectly checks WarningsAsMessages instead of WarningsAsErrors. return (WarningsAsErrors.Count == 0 && WarningAsErrorNotOverriden(warningCode)) || WarningsAsMessages.Contains(warningCode); } From 950670e25f8bc302a11f46f5598835ecf72ba43b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:31:59 +0000 Subject: [PATCH 4/5] Replace reflection-based unit tests with TaskHostFactory integration tests Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/c040bcf1-9dab-4b98-9019-bb39ce5175ab --- .../WarningsAsMessagesAndErrors_Tests.cs | 94 +++++++++ .../OutOfProcTaskHostNode_Tests.cs | 182 ------------------ 2 files changed, 94 insertions(+), 182 deletions(-) delete mode 100644 src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs diff --git a/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs b/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs index b6752b6b87f..ae9b60a2fc5 100644 --- a/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs +++ b/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.UnitTests; @@ -673,5 +674,98 @@ public void DuplicateDiagnosticCodesInNoWarnAndMSBuildWarningsAsMessagesAreHandl logger.ErrorCount.ShouldBe(0); } } + /// + /// Verifies that when a task runs out-of-proc via TaskHostFactory and logs a warning + /// whose code is in MSBuildWarningsAsErrors, the warning is promoted to an error. + /// This was broken before ChangeWave 18.6 (the OOP code checked WarningsAsMessages + /// instead of WarningsAsErrors). + /// + [Fact] + public void TreatWarningsAsErrorsWhenSpecified_TaskHostFactory() + { + string assemblyLocation = Path.Combine( + Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, + "Microsoft.Build.Engine.UnitTests.dll"); + + using TestEnvironment env = TestEnvironment.Create(_output); + + TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" + + + + {ExpectedEventCode} + + + + + "); + + MockLogger logger = proj.BuildProjectExpectFailure(); + + logger.ErrorCount.ShouldBe(1); + logger.WarningCount.ShouldBe(0); + logger.AssertLogContains(ExpectedEventCode); + } + + /// + /// Verifies that when a task runs out-of-proc via TaskHostFactory and + /// MSBuildTreatWarningsAsErrors is true, all warnings are promoted to errors. + /// + [Fact] + public void TreatAllWarningsAsErrors_TaskHostFactory() + { + string assemblyLocation = Path.Combine( + Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, + "Microsoft.Build.Engine.UnitTests.dll"); + + using TestEnvironment env = TestEnvironment.Create(_output); + + TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" + + + + true + + + + + "); + + MockLogger logger = proj.BuildProjectExpectFailure(); + + logger.ErrorCount.ShouldBe(1); + logger.WarningCount.ShouldBe(0); + } + + /// + /// Verifies that WarningsAsMessages takes priority over WarningsAsErrors + /// when a task runs out-of-proc via TaskHostFactory. + /// + [Fact] + public void TreatWarningAsMessageOverridesTreatingItAsError_TaskHostFactory() + { + string assemblyLocation = Path.Combine( + Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, + "Microsoft.Build.Engine.UnitTests.dll"); + + using TestEnvironment env = TestEnvironment.Create(_output); + + TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" + + + + {ExpectedEventCode} + {ExpectedEventCode} + + + + + "); + + MockLogger logger = proj.BuildProjectExpectSuccess(); + + logger.ErrorCount.ShouldBe(0); + logger.WarningCount.ShouldBe(0); + } } } diff --git a/src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs b/src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs deleted file mode 100644 index fc9fcfb5023..00000000000 --- a/src/MSBuild.UnitTests/OutOfProcTaskHostNode_Tests.cs +++ /dev/null @@ -1,182 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using Microsoft.Build.CommandLine; -using Microsoft.Build.Framework; -using Microsoft.Build.Shared; -using Microsoft.Build.UnitTests; -using Shouldly; -using Xunit; -using Xunit.Abstractions; - -#nullable disable - -namespace Microsoft.Build.CommandLine.UnitTests -{ - public sealed class OutOfProcTaskHostNode_Tests - { - private readonly ITestOutputHelper _output; - - public OutOfProcTaskHostNode_Tests(ITestOutputHelper output) - { - _output = output; - } - - [Fact] - public void ShouldTreatWarningAsError_SpecificCode_ReturnsTrue() - { - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet { "MY0001" }); - SetWarningsAsMessages(node, null); - SetWarningsNotAsErrors(node, null); - - node.ShouldTreatWarningAsError("MY0001").ShouldBeTrue(); - } - - [Fact] - public void ShouldTreatWarningAsError_SpecificCode_OtherCode_ReturnsFalse() - { - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet { "MY0001" }); - SetWarningsAsMessages(node, null); - SetWarningsNotAsErrors(node, null); - - node.ShouldTreatWarningAsError("OTHER0001").ShouldBeFalse(); - } - - [Fact] - public void ShouldTreatWarningAsError_TreatAll_ReturnsTrue() - { - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet()); - SetWarningsAsMessages(node, null); - SetWarningsNotAsErrors(node, null); - - node.ShouldTreatWarningAsError("ANY0001").ShouldBeTrue(); - } - - [Fact] - public void ShouldTreatWarningAsError_TreatAll_OverriddenByNotAsErrors_ReturnsFalse() - { - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet()); - SetWarningsAsMessages(node, null); - SetWarningsNotAsErrors(node, new HashSet { "MY0001" }); - - node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); - } - - [Fact] - public void ShouldTreatWarningAsError_Null_ReturnsFalse() - { - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, null); - SetWarningsAsMessages(node, null); - SetWarningsNotAsErrors(node, null); - - node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); - } - - [Fact] - public void ShouldTreatWarningAsError_WarningAsMessage_ReturnsFalse() - { - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet { "MY0001" }); - SetWarningsAsMessages(node, new HashSet { "MY0001" }); - SetWarningsNotAsErrors(node, null); - - // WarningsAsMessages overrides WarningsAsErrors - node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); - } - - [Fact] - public void ShouldTreatWarningAsError_SpecificCode_NullWarningsAsMessages_ReturnsTrue() - { - // This is the exact scenario from the bug report: - // WarningsAsErrors = {"MY0001"}, WarningsAsMessages = null - // The old buggy code would NRE on WarningsAsMessages.Contains(). - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", string.Empty); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet { "MY0001" }); - SetWarningsAsMessages(node, null); - SetWarningsNotAsErrors(node, null); - - node.ShouldTreatWarningAsError("MY0001").ShouldBeTrue(); - } - - [Fact] - public void ShouldTreatWarningAsError_SpecificCode_ChangeWaveDisabled_PreservesOldBehavior() - { - // When ChangeWave 18.6 is disabled, the old buggy behavior is preserved. - using TestEnvironment env = TestEnvironment.Create(_output); - ChangeWaves.ResetStateForTests(); - env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave18_6.ToString()); - BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); - - OutOfProcTaskHostNode node = new(); - SetWarningsAsErrors(node, new HashSet { "MY0001" }); - SetWarningsAsMessages(node, new HashSet()); - SetWarningsNotAsErrors(node, null); - - // With old behavior, WarningsAsMessages.Contains("MY0001") is checked instead of WarningsAsErrors, - // so this returns false (bug). - node.ShouldTreatWarningAsError("MY0001").ShouldBeFalse(); - } - - private static void SetWarningsAsErrors(OutOfProcTaskHostNode node, ICollection value) - { - typeof(OutOfProcTaskHostNode) - .GetProperty("WarningsAsErrors", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) - .SetValue(node, value); - } - - private static void SetWarningsAsMessages(OutOfProcTaskHostNode node, ICollection value) - { - typeof(OutOfProcTaskHostNode) - .GetProperty("WarningsAsMessages", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) - .SetValue(node, value); - } - - private static void SetWarningsNotAsErrors(OutOfProcTaskHostNode node, ICollection value) - { - typeof(OutOfProcTaskHostNode) - .GetProperty("WarningsNotAsErrors", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) - .SetValue(node, value); - } - } -} From 3b98feaa1c6468daa4f56da81a89ea2188b8f46d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:35:25 +0000 Subject: [PATCH 5/5] Extract TestAssemblyLocation to shared field to reduce duplication Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/c040bcf1-9dab-4b98-9019-bb39ce5175ab --- .../WarningsAsMessagesAndErrors_Tests.cs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs b/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs index ae9b60a2fc5..10ce4eba75b 100644 --- a/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs +++ b/src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs @@ -19,6 +19,9 @@ public sealed class WarningsAsMessagesAndErrorsTests { private const string ExpectedEventMessage = "03767942CDB147B98D0ECDBDE1436DA3"; private const string ExpectedEventCode = "0BF68998"; + private static string TestAssemblyLocation { get; } = Path.Combine( + Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, + "Microsoft.Build.Engine.UnitTests.dll"); private ITestOutputHelper _output; public WarningsAsMessagesAndErrorsTests(ITestOutputHelper output) @@ -683,15 +686,11 @@ public void DuplicateDiagnosticCodesInNoWarnAndMSBuildWarningsAsMessagesAreHandl [Fact] public void TreatWarningsAsErrorsWhenSpecified_TaskHostFactory() { - string assemblyLocation = Path.Combine( - Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, - "Microsoft.Build.Engine.UnitTests.dll"); - using TestEnvironment env = TestEnvironment.Create(_output); TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" - + {ExpectedEventCode} @@ -714,15 +713,11 @@ public void TreatWarningsAsErrorsWhenSpecified_TaskHostFactory() [Fact] public void TreatAllWarningsAsErrors_TaskHostFactory() { - string assemblyLocation = Path.Combine( - Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, - "Microsoft.Build.Engine.UnitTests.dll"); - using TestEnvironment env = TestEnvironment.Create(_output); TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" - + true @@ -744,15 +739,11 @@ public void TreatAllWarningsAsErrors_TaskHostFactory() [Fact] public void TreatWarningAsMessageOverridesTreatingItAsError_TaskHostFactory() { - string assemblyLocation = Path.Combine( - Path.GetDirectoryName(typeof(WarningsAsMessagesAndErrorsTests).Assembly.Location) ?? AppContext.BaseDirectory, - "Microsoft.Build.Engine.UnitTests.dll"); - using TestEnvironment env = TestEnvironment.Create(_output); TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@" - + {ExpectedEventCode} {ExpectedEventCode}