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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<!-- Expose a test target usable by tests projects where this target is injected -->
<Target Name="Test" Condition=" '$(UseMSBuildTestInfrastructure)' != 'True' " >
<CallTarget Targets="_TestingPlatformTest" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@
<CallTarget Targets="_TestingPlatformTest" />
</Target>

<!-- Expose a test target usable by tests projects where this target is injected -->
<Target Name="Test" Condition=" '$(UseMSBuildTestInfrastructure)' != 'True' AND '$(TestingPlatformDisableCustomTestTarget)' == 'False' " >
<CallTarget Targets="_TestingPlatformTest" />
</Target>
<!-- The Test target is separated so that we can conditionally define it. -->
<!-- Putting a condition on a target determines whether the target is **executed** or not -->
<!-- We want to not define the Test target in the first place when the user sets TestingPlatformDisableCustomTestTarget to true -->
<Import Project="Microsoft.Testing.Platform.MSBuild.CustomTestTarget.targets" Condition="'$(TestingPlatformDisableCustomTestTarget)' == 'False'" />

<Target Name="_TestingPlatformTest">
<!-- We call VSTest built-in workflow only for the multi-tfm for single tfm we need to directly call our target -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$", "<PlatformTarget>x64</PlatformTarget>")
.PatchCodeWithReplace("$TargetFrameworks$", $"<TargetFramework>{TargetFrameworks.NetCurrent}</TargetFramework>")
.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
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -270,6 +285,15 @@ public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="$MicrosoftTestingPlatformVersion$" />
<PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" />
</ItemGroup>

<Import Project="UserDefinedTestTarget.targets" Condition="'$(ImportUserDefinedTestTarget)' == 'true'" />
</Project>

#file UserDefinedTestTarget.targets
<Project>
<Target Name="Test">
<Error Text="Error from UserDefinedTestTarget.targets" />
</Target>
</Project>

#file Program.cs
Expand Down