From 526597686d8e82a65f2ca40fb818ef1eeb4a609d Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 30 Jan 2025 12:27:08 +0100 Subject: [PATCH] Don't inject Test target when `TestingPlatformDisableCustomTestTarget` is true (#4838) --- ....Platform.MSBuild.CustomTestTarget.targets | 6 +++++ ...Microsoft.Testing.Platform.MSBuild.targets | 8 +++---- .../MSBuildTests.Test.cs | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.CustomTestTarget.targets diff --git a/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.CustomTestTarget.targets b/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.CustomTestTarget.targets new file mode 100644 index 0000000000..abd9d23857 --- /dev/null +++ b/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.CustomTestTarget.targets @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.targets b/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.targets index 48eea935a1..fb3aee43d5 100644 --- a/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.targets +++ b/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.targets @@ -267,10 +267,10 @@ - - - - + + + + diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs index 212ee2da71..9360c2525c 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs @@ -252,6 +252,21 @@ public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_ compilationResult.AssertOutputContains(".NET Testing Platform"); } + [TestMethod] + public async Task TestingPlatformDisableCustomTestTarget_Should_Cause_UserDefined_Target_To_Run() + { + using TestAsset testAsset = await TestAsset.GenerateAssetAsync( + AssetName, + SourceCode + .PatchCodeWithReplace("$PlatformTarget$", "x64") + .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent}") + .PatchCodeWithReplace("$AssertValue$", "true") + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build {testAsset.TargetAssetPath} -p:TestingPlatformDisableCustomTestTarget=true -p:ImportUserDefinedTestTarget=true -t:\"Build;Test\"", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); + + compilationResult.AssertOutputContains("Error from UserDefinedTestTarget.targets"); + } + private const string SourceCode = """ #file MSBuild Tests.csproj @@ -270,6 +285,15 @@ public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_ + + + + +#file UserDefinedTestTarget.targets + + + + #file Program.cs