Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [Fix ToolTask hang when tool spawns grandchild processes that inherit stdout/stderr pipe handles](https://github.com/dotnet/msbuild/issues/2981)

### 18.5
Expand Down
85 changes: 85 additions & 0 deletions src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.UnitTests;
Expand All @@ -18,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)
Expand Down Expand Up @@ -673,5 +677,86 @@ public void DuplicateDiagnosticCodesInNoWarnAndMSBuildWarningsAsMessagesAreHandl
logger.ErrorCount.ShouldBe(0);
}
}
/// <summary>
/// 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).
/// </summary>
[Fact]
public void TreatWarningsAsErrorsWhenSpecified_TaskHostFactory()
{
using TestEnvironment env = TestEnvironment.Create(_output);

TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@"
<Project>
<UsingTask TaskName=""CustomLogAndReturnTask"" AssemblyFile=""{TestAssemblyLocation}"" TaskFactory=""TaskHostFactory"" />
<PropertyGroup>
<MSBuildWarningsAsErrors>{ExpectedEventCode}</MSBuildWarningsAsErrors>
</PropertyGroup>
<Target Name='Build'>
<CustomLogAndReturnTask Return=""true"" WarningCode=""{ExpectedEventCode}""/>
</Target>
</Project>");

MockLogger logger = proj.BuildProjectExpectFailure();

logger.ErrorCount.ShouldBe(1);
logger.WarningCount.ShouldBe(0);
logger.AssertLogContains(ExpectedEventCode);
}

/// <summary>
/// Verifies that when a task runs out-of-proc via TaskHostFactory and
/// MSBuildTreatWarningsAsErrors is true, all warnings are promoted to errors.
/// </summary>
[Fact]
public void TreatAllWarningsAsErrors_TaskHostFactory()
{
using TestEnvironment env = TestEnvironment.Create(_output);

TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@"
<Project>
<UsingTask TaskName=""CustomLogAndReturnTask"" AssemblyFile=""{TestAssemblyLocation}"" TaskFactory=""TaskHostFactory"" />
<PropertyGroup>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
</PropertyGroup>
<Target Name='Build'>
<CustomLogAndReturnTask Return=""true"" WarningCode=""{ExpectedEventCode}""/>
</Target>
</Project>");

MockLogger logger = proj.BuildProjectExpectFailure();

logger.ErrorCount.ShouldBe(1);
logger.WarningCount.ShouldBe(0);
}

/// <summary>
/// Verifies that WarningsAsMessages takes priority over WarningsAsErrors
/// when a task runs out-of-proc via TaskHostFactory.
/// </summary>
[Fact]
public void TreatWarningAsMessageOverridesTreatingItAsError_TaskHostFactory()
{
using TestEnvironment env = TestEnvironment.Create(_output);

TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@"
<Project>
<UsingTask TaskName=""CustomLogAndReturnTask"" AssemblyFile=""{TestAssemblyLocation}"" TaskFactory=""TaskHostFactory"" />
<PropertyGroup>
<MSBuildWarningsAsErrors>{ExpectedEventCode}</MSBuildWarningsAsErrors>
<MSBuildWarningsAsMessages>{ExpectedEventCode}</MSBuildWarningsAsMessages>
</PropertyGroup>
<Target Name='Build'>
<CustomLogAndReturnTask Return=""true"" WarningCode=""{ExpectedEventCode}""/>
</Target>
</Project>");

MockLogger logger = proj.BuildProjectExpectSuccess();

logger.ErrorCount.ShouldBe(0);
logger.WarningCount.ShouldBe(0);
}
}
}
7 changes: 7 additions & 0 deletions src/MSBuild/OutOfProcTaskHostNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 behavior preserved for backward compatibility: incorrectly checks WarningsAsMessages instead of WarningsAsErrors.
return (WarningsAsErrors.Count == 0 && WarningAsErrorNotOverriden(warningCode)) || WarningsAsMessages.Contains(warningCode);
Comment thread
JanProvaznik marked this conversation as resolved.
}

Expand Down