|
|
|
|
@@ -0,0 +1,376 @@
|
|
|
|
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
|
|
|
|
|
|
|
|
|
<!-- Setup the task folder -->
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- Constants -->
|
|
|
|
|
<MicrosoftTestingPlatformMSBuildTaskFolder Condition=" $(MicrosoftTestingPlatformMSBuildTaskFolder) == '' ">$(MSBuildThisFileDirectory)..\_MSBuildTasks\netstandard2.0\</MicrosoftTestingPlatformMSBuildTaskFolder>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
Configuration file generation
|
|
|
|
|
===========================
|
|
|
|
|
|
|
|
|
|
The configuration file is generated by the GenerateTestingPlatformConfigurationFile target.
|
|
|
|
|
We copy the file called testconfig.json from the project directory to the output directory.
|
|
|
|
|
The file is copied only if it does not exist in the output directory or if it has changed.
|
|
|
|
|
The file is copied to the output directory before the CopyFilesToOutputDirectory target is executed.
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!-- Import task -->
|
|
|
|
|
<UsingTask TaskName="Microsoft.Testing.Platform.MSBuild.ConfigurationFileTask"
|
|
|
|
|
AssemblyFile="$(MicrosoftTestingPlatformMSBuildTaskFolder)Microsoft.Testing.Platform.MSBuild.dll"/>
|
|
|
|
|
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<_TestingPlatformConfigurationFileSourceFileName>testconfig.json</_TestingPlatformConfigurationFileSourceFileName>
|
|
|
|
|
<_TestingPlatformConfigurationFileSourcePath>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),$(_TestingPlatformConfigurationFileSourceFileName)))</_TestingPlatformConfigurationFileSourcePath>
|
|
|
|
|
<_TestingPlatformConfigurationFileName>$(AssemblyName).testconfig.json</_TestingPlatformConfigurationFileName>
|
|
|
|
|
<_TestingPlatformConfigurationFile>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),$(OutputPath),$(_TestingPlatformConfigurationFileName)))</_TestingPlatformConfigurationFile>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
|
|
|
|
|
<Target Name="_CalculateGenerateTestingPlatformConfigurationFile">
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- We add this to a target to allow setting IsTestingPlatformApplication as late as possible -->
|
|
|
|
|
<!-- For example, MSTest.TestAdapter.targets is imported *after* Microsoft.Testing.Platform.MSBuild.targets -->
|
|
|
|
|
<!-- We want to allow MSTest.TestAdapter.targets to set IsTestingPlatformApplication to false if EnableMSTestRunner is not set to true. -->
|
|
|
|
|
<GenerateTestingPlatformConfigurationFile Condition=" '$(GenerateTestingPlatformConfigurationFile)' == '' " >$(IsTestingPlatformApplication)</GenerateTestingPlatformConfigurationFile>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<Target Name="GenerateTestingPlatformConfigurationFile" BeforeTargets="CopyFilesToOutputDirectory"
|
|
|
|
|
DependsOnTargets="_CalculateGenerateTestingPlatformConfigurationFile;_GenerateTestingPlatformConfigurationFileCore" />
|
|
|
|
|
|
|
|
|
|
<Target Name="_GenerateTestingPlatformConfigurationFileCore"
|
|
|
|
|
Inputs="$(_TestingPlatformConfigurationFileSourcePath)"
|
|
|
|
|
Outputs="$(_TestingPlatformConfigurationFile)"
|
|
|
|
|
Condition=" '$(GenerateTestingPlatformConfigurationFile)' == 'true' And Exists('$(_TestingPlatformConfigurationFileSourcePath)') " >
|
|
|
|
|
<ConfigurationFileTask
|
|
|
|
|
MSBuildProjectDirectory="$(MSBuildProjectDirectory)"
|
|
|
|
|
AssemblyName="$(AssemblyName)"
|
|
|
|
|
OutputPath="$(OutputPath)"
|
|
|
|
|
TestingPlatformConfigurationFileSource="$(_TestingPlatformConfigurationFileSourcePath)" >
|
|
|
|
|
<Output TaskParameter="FinalTestingPlatformConfigurationFile" ItemName="TestingPlatformConfigurationFile" />
|
|
|
|
|
</ConfigurationFileTask>
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<FileWrites Include="$(_TestingPlatformConfigurationFile)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<ResolvedFileToPublish Include="$(_TestingPlatformConfigurationFile)" >
|
|
|
|
|
<RelativePath>$(_TestingPlatformConfigurationFileName)</RelativePath>
|
|
|
|
|
</ResolvedFileToPublish>
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
Inject application entry point a.k.a. Program.* file
|
|
|
|
|
===========================
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!-- Import task -->
|
|
|
|
|
<UsingTask TaskName="Microsoft.Testing.Platform.MSBuild.TestingPlatformEntryPointTask"
|
|
|
|
|
AssemblyFile="$(MicrosoftTestingPlatformMSBuildTaskFolder)Microsoft.Testing.Platform.MSBuild.dll"/>
|
|
|
|
|
|
|
|
|
|
<Target Name="_CalculateGenerateTestingPlatformEntryPoint">
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- We add this to a target to allow setting IsTestingPlatformApplication as late as possible -->
|
|
|
|
|
<!-- For example, MSTest.TestAdapter.targets is imported *after* Microsoft.Testing.Platform.MSBuild.targets -->
|
|
|
|
|
<!-- We want to allow MSTest.TestAdapter.targets to set IsTestingPlatformApplication to false if EnableMSTestRunner is not set to true. -->
|
|
|
|
|
<GenerateTestingPlatformEntryPoint Condition=" '$(GenerateTestingPlatformEntryPoint)' == '' " >$(IsTestingPlatformApplication)</GenerateTestingPlatformEntryPoint>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<Target Name="_GenerateTestingPlatformEntryPointFileInputCache" DependsOnTargets="_CalculateGenerateTestingPlatformEntryPoint">
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- Cache file to check -->
|
|
|
|
|
<_GenerateTestingPlatformEntryPointInputsCachFilePath>$(IntermediateOutputPath)$(MSBuildProjectName).gentestingplatformentrypointinputcache.cache</_GenerateTestingPlatformEntryPointInputsCachFilePath>
|
|
|
|
|
<_GenerateTestingPlatformEntryPointInputsCachFilePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GenerateTestingPlatformEntryPointInputsCachFilePath)))</_GenerateTestingPlatformEntryPointInputsCachFilePath>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<!-- Items to hash-->
|
|
|
|
|
<_GenerateTestingPlatformEntryPointInputsCacheToHash Include="@(TestingPlatformBuilderHook)"/>
|
|
|
|
|
<_GenerateTestingPlatformEntryPointInputsCacheToHash Include="$(RootNamespace)"/>
|
|
|
|
|
<_GenerateTestingPlatformEntryPointInputsCacheToHash Include="$(GenerateTestingPlatformEntryPoint)" />
|
|
|
|
|
|
|
|
|
|
<!-- Export the items name for the _GenerateTestingPlatformInjectEntryPoint task-->
|
|
|
|
|
<GenerateTestingPlatformEntryPointInputsCacheFilePath Include="$(_GenerateTestingPlatformEntryPointInputsCachFilePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
<!-- Hash the extensions information -->
|
|
|
|
|
<Hash ItemsToHash="@(_GenerateTestingPlatformEntryPointInputsCacheToHash)">
|
|
|
|
|
<Output TaskParameter="HashResult" PropertyName="_GenerateTestingPlatformEntryPointInputsCache" />
|
|
|
|
|
</Hash>
|
|
|
|
|
<!-- Write the hash value to the cache file -->
|
|
|
|
|
<WriteLinesToFile Lines="$(_GenerateTestingPlatformEntryPointInputsCache)"
|
|
|
|
|
File="$(_GenerateTestingPlatformEntryPointInputsCachFilePath)"
|
|
|
|
|
Overwrite="true"
|
|
|
|
|
WriteOnlyWhenDifferent="true" />
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<FileWrites Include="$(_GenerateTestingPlatformEntryPointInputsCachFilePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!-- Generate the entry point source using the user extensions informations -->
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<_TestingPlatformEntryPointSourceName>MicrosoftTestingPlatformEntryPoint$(DefaultLanguageSourceExtension)</_TestingPlatformEntryPointSourceName>
|
|
|
|
|
<_TestingPlatformEntryPointSourcePath>$([System.IO.Path]::Combine($(IntermediateOutputPath),$(_TestingPlatformEntryPointSourceName)))</_TestingPlatformEntryPointSourcePath>
|
|
|
|
|
<_TestingPlatformEntryPointSourcePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_TestingPlatformEntryPointSourcePath)))</_TestingPlatformEntryPointSourcePath>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
<Target Name="_GenerateTestingPlatformEntryPoint"
|
|
|
|
|
Inputs="@(GenerateTestingPlatformEntryPointInputsCacheFilePath)" Outputs="$(_TestingPlatformEntryPointSourcePath)"
|
|
|
|
|
Condition=" '$(GenerateTestingPlatformEntryPoint)' == 'true' " >
|
|
|
|
|
<TestingPlatformEntryPointTask TestingPlatformEntryPointSourcePath="$(_TestingPlatformEntryPointSourcePath)"
|
|
|
|
|
RootNamespace="$(RootNamespace)"
|
|
|
|
|
Language="$(Language)" >
|
|
|
|
|
<Output TaskParameter="TestingPlatformEntryPointGeneratedFilePath" PropertyName ="TestingPlatformEntryPointGeneratedFilePath" />
|
|
|
|
|
</TestingPlatformEntryPointTask>
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<FileWrites Include="$(_TestingPlatformEntryPointSourcePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<Target Name="_IncludeGenerateTestingPlatformEntryPointIntoCompilation" BeforeTargets="BeforeCompile;XamlPreCompile"
|
|
|
|
|
DependsOnTargets="_CalculateGenerateTestingPlatformEntryPoint;_GenerateTestingPlatformEntryPointFileInputCache;_GenerateTestingPlatformEntryPoint">
|
|
|
|
|
|
|
|
|
|
<ItemGroup Condition=" '$(GenerateTestingPlatformEntryPoint)' == 'true' ">
|
|
|
|
|
<!-- Order of files matter in F#. Make sure to include the entry-point last. -->
|
|
|
|
|
<!-- See https://github.com/dotnet/fsharp/blob/27db996c58a511386ad754e34f4b57877aa1d99e/src/FSharp.Build/Microsoft.FSharp.Targets#L258-L277 -->
|
|
|
|
|
<!-- IMPORTANT: We use CompileAfter and not CompileLast as CompileLast is quite recent: https://github.com/dotnet/fsharp/pull/17103 -->
|
|
|
|
|
<!-- Note that we only add the entry point in CompileAfter. The self-registered extensions is still in Compile -->
|
|
|
|
|
<!-- If the user enables only self-registered extensions generation and decides to write their own entry point, they should add
|
|
|
|
|
their entry point file to CompileAfter as well -->
|
|
|
|
|
<Compile Include="$(_TestingPlatformEntryPointSourcePath)" Condition=" '$(Language)' != 'F#' " />
|
|
|
|
|
<CompileAfter Include="$(_TestingPlatformEntryPointSourcePath)" Condition=" '$(Language)' == 'F#' " />
|
|
|
|
|
|
|
|
|
|
<!-- We need to report to the FileWrites here because is possible that we skip _GenerateTestingPlatformInjectEntryPoint and we want to correctly handle the "dotnet clean" target -->
|
|
|
|
|
<FileWrites Include="$(_TestingPlatformEntryPointSourcePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
Inject SelfRegisteredExtensions
|
|
|
|
|
===========================
|
|
|
|
|
|
|
|
|
|
Expected extensions items shape
|
|
|
|
|
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<TestingPlatformBuilderHook Include="8E680F4D-E423-415A-9566-855439363BC0" >
|
|
|
|
|
<DisplayName>MyBuilderHook</DisplayName>
|
|
|
|
|
<TypeFullName>Contoso.BuilderHook</TypeFullName>
|
|
|
|
|
</TestingPlatformBuilderHook>
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!-- Import task -->
|
|
|
|
|
<UsingTask TaskName="Microsoft.Testing.Platform.MSBuild.TestingPlatformSelfRegisteredExtensions"
|
|
|
|
|
AssemblyFile="$(MicrosoftTestingPlatformMSBuildTaskFolder)Microsoft.Testing.Platform.MSBuild.dll"/>
|
|
|
|
|
|
|
|
|
|
<Target Name="_CalculateGenerateSelfRegisteredExtensions">
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- We add this to a target to allow setting IsTestingPlatformApplication as late as possible -->
|
|
|
|
|
<!-- For example, MSTest.TestAdapter.targets is imported *after* Microsoft.Testing.Platform.MSBuild.targets -->
|
|
|
|
|
<!-- We want to allow MSTest.TestAdapter.targets to set IsTestingPlatformApplication to false if EnableMSTestRunner is not set to true. -->
|
|
|
|
|
<GenerateSelfRegisteredExtensions Condition=" '$(GenerateSelfRegisteredExtensions)' == '' " >$(IsTestingPlatformApplication)</GenerateSelfRegisteredExtensions>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<Target Name="_GenerateSelfRegisteredExtensionsFileInputCache" DependsOnTargets="_CalculateGenerateSelfRegisteredExtensions">
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- Cache file to check -->
|
|
|
|
|
<_GenerateSelfRegisteredExtensionsInputsCachFilePath>$(IntermediateOutputPath)$(MSBuildProjectName).genautoregisteredextensionsinputcache.cache</_GenerateSelfRegisteredExtensionsInputsCachFilePath>
|
|
|
|
|
<_GenerateSelfRegisteredExtensionsInputsCachFilePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GenerateSelfRegisteredExtensionsInputsCachFilePath)))</_GenerateSelfRegisteredExtensionsInputsCachFilePath>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<!-- Items to hash-->
|
|
|
|
|
<_GenerateSelfRegisteredExtensionsInputsCacheToHash Include="@(TestingPlatformBuilderHook)"/>
|
|
|
|
|
<_GenerateSelfRegisteredExtensionsInputsCacheToHash Include="$(RootNamespace)"/>
|
|
|
|
|
<_GenerateSelfRegisteredExtensionsInputsCacheToHash Include="$(GenerateSelfRegisteredExtensions)"/>
|
|
|
|
|
|
|
|
|
|
<!-- Export the items name for the _GenerateSelfRegisteredExtensions task-->
|
|
|
|
|
<GenerateSelfRegisteredExtensionsInputsCacheFilePath Include="$(_GenerateSelfRegisteredExtensionsInputsCachFilePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
<!-- Hash the extensions information -->
|
|
|
|
|
<Hash ItemsToHash="@(_GenerateSelfRegisteredExtensionsInputsCacheToHash)">
|
|
|
|
|
<Output TaskParameter="HashResult" PropertyName="_GenerateSelfRegisteredExtensionsInputsCache" />
|
|
|
|
|
</Hash>
|
|
|
|
|
<!-- Write the hash value to the cache file -->
|
|
|
|
|
<WriteLinesToFile Lines="$(_GenerateSelfRegisteredExtensionsInputsCache)"
|
|
|
|
|
File="$(_GenerateSelfRegisteredExtensionsInputsCachFilePath)"
|
|
|
|
|
Overwrite="true"
|
|
|
|
|
WriteOnlyWhenDifferent="true" />
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<FileWrites Include="$(_GenerateSelfRegisteredExtensionsInputsCachFilePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!-- Generate the extensions source file using the user extensions informations -->
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<_SelfRegisteredExtensionsSourceName>SelfRegisteredExtensions$(DefaultLanguageSourceExtension)</_SelfRegisteredExtensionsSourceName>
|
|
|
|
|
<_SelfRegisteredExtensionsSourcePath>$([System.IO.Path]::Combine($(IntermediateOutputPath),$(_SelfRegisteredExtensionsSourceName)))</_SelfRegisteredExtensionsSourcePath>
|
|
|
|
|
<_SelfRegisteredExtensionsSourcePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_SelfRegisteredExtensionsSourcePath)))</_SelfRegisteredExtensionsSourcePath>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
<Target Name="_GenerateSelfRegisteredExtensions"
|
|
|
|
|
Inputs="@(GenerateSelfRegisteredExtensionsInputsCacheFilePath)" Outputs="$(_SelfRegisteredExtensionsSourcePath)"
|
|
|
|
|
Condition=" '$(GenerateSelfRegisteredExtensions)' == 'true' " >
|
|
|
|
|
<TestingPlatformSelfRegisteredExtensions SelfRegisteredExtensionsSourcePath="$(_SelfRegisteredExtensionsSourcePath)"
|
|
|
|
|
SelfRegisteredExtensionsBuilderHook="@(TestingPlatformBuilderHook)"
|
|
|
|
|
RootNamespace="$(RootNamespace)"
|
|
|
|
|
Language="$(Language)" >
|
|
|
|
|
<Output TaskParameter="SelfRegisteredExtensionsGeneratedFilePath" PropertyName ="SelfRegisteredExtensionsGeneratedFilePath" />
|
|
|
|
|
</TestingPlatformSelfRegisteredExtensions>
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<FileWrites Include="$(_SelfRegisteredExtensionsSourcePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!-- We always include the entry point also if the task _GenerateSelfRegisteredExtensions is skipped for caching reason -->
|
|
|
|
|
<!-- !!! DO NOT CHANGE THE NAME OF THIS TARGET IS USED BY ADAPTERS https://github.com/microsoft/testfx/issues/3478#issuecomment-2313889212 !!! -->
|
|
|
|
|
<Target Name="_IncludeGenerateAutoRegisteredExtensionsIntoCompilation" BeforeTargets="BeforeCompile;XamlPreCompile"
|
|
|
|
|
DependsOnTargets="_CalculateGenerateSelfRegisteredExtensions;_GenerateSelfRegisteredExtensionsFileInputCache;_GenerateSelfRegisteredExtensions">
|
|
|
|
|
|
|
|
|
|
<ItemGroup Condition=" '$(GenerateSelfRegisteredExtensions)' == 'true' ">
|
|
|
|
|
<Compile Include="$(_SelfRegisteredExtensionsSourcePath)" />
|
|
|
|
|
|
|
|
|
|
<!-- We need to report to the FileWrites here because is possible that we skip _GenerateSelfRegisteredExtensions and we want to correctly handle the "dotnet clean" target -->
|
|
|
|
|
<FileWrites Include="$(_SelfRegisteredExtensionsSourcePath)" />
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
Hook the testing platform
|
|
|
|
|
===========================
|
|
|
|
|
|
|
|
|
|
Entry points targets:
|
|
|
|
|
* VSTest: Overrides the SDK VSTest target for single tfm, we use the built-in multitfm workflow https://github.com/dotnet/sdk/blob/main/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.CrossTargeting.targets/ImportAfter/Microsoft.TestPlatform.CrossTargeting.targets#L79
|
|
|
|
|
* Test: We plug ourself to the available VSTest target for multitfm and we go directly to our target for single tfm
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!-- Import task -->
|
|
|
|
|
<UsingTask TaskName="Microsoft.Testing.Platform.MSBuild.InvokeTestingPlatformTask"
|
|
|
|
|
AssemblyFile="$(MicrosoftTestingPlatformMSBuildTaskFolder)Microsoft.Testing.Platform.MSBuild.dll"/>
|
|
|
|
|
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- Disable custom -t:Test target -->
|
|
|
|
|
<TestingPlatformDisableCustomTestTarget Condition=" '$(TestingPlatformDisableCustomTestTarget)' == '' ">False</TestingPlatformDisableCustomTestTarget>
|
|
|
|
|
<!-- Support dotnet test -->
|
|
|
|
|
<TestingPlatformDotnetTestSupport Condition=" '$(TestingPlatformDotnetTestSupport)' == '' ">False</TestingPlatformDotnetTestSupport>
|
|
|
|
|
<!--
|
|
|
|
|
Verify if the <UseMSBuildTestInfrastructure> is available
|
|
|
|
|
https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.CurrentVersion.targets#L6807
|
|
|
|
|
https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.Test.targets
|
|
|
|
|
-->
|
|
|
|
|
<_MSBuildTestInfrastructureAvailable Condition="Exists('$(MSBuildExtensionsPath)\Microsoft.Common.Test.targets')" >true</_MSBuildTestInfrastructureAvailable>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
|
|
|
|
|
<Target Name="_SetCustomVSTargetForVSTest" BeforeTargets="VSTest" Condition=" '$(TestingPlatformDotnetTestSupport)' == 'true' ">
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!-- Set our VSTest target for the multi-tfm workflow -->
|
|
|
|
|
<InnerVSTestTargets Condition=" '$(TestingPlatformDotnetTestSupport)' == 'true' " >InvokeTestingPlatform</InnerVSTestTargets>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
<!-- Override VSTest only in case of single tfm, for multitfm we rely on built-in mechanism -->
|
|
|
|
|
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Testing.Platform.MSBuild.VSTest.targets"
|
|
|
|
|
Condition=" '$(TargetFramework)' != '' AND '$(TestingPlatformDotnetTestSupport)' == 'true' "/>
|
|
|
|
|
|
|
|
|
|
<!-- Rely on VSTest infra -->
|
|
|
|
|
<!-- We setup the InnerVSTestTargets is we're using the MSBuild infrastructure or if user didn't disble the custom test target -->
|
|
|
|
|
<Target Name="_SetCustomVSTargetForTest" BeforeTargets="Test" Condition=" ( '$(UseMSBuildTestInfrastructure)' == 'true' AND '$(_MSBuildTestInfrastructureAvailable)' == 'true' ) OR '$(TestingPlatformDisableCustomTestTarget)' == 'False' " >
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<InnerVSTestTargets>InvokeTestingPlatform</InnerVSTestTargets>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!-- Plug with the new msbuild target
|
|
|
|
|
https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.CurrentVersion.targets#L6807
|
|
|
|
|
https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.Test.targets
|
|
|
|
|
-->
|
|
|
|
|
<Target Name="_MSBuildTest" AfterTargets="Test" Condition=" '$(UseMSBuildTestInfrastructure)' == 'true' AND '$(_MSBuildTestInfrastructureAvailable)' == 'true' " >
|
|
|
|
|
<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 -->
|
|
|
|
|
<CallTarget Targets="VSTest" Condition=" '$(TargetFramework)' == '' "/>
|
|
|
|
|
<!-- For single tfm we call directly our target like we're doing for single tfm and VSTest -->
|
|
|
|
|
<CallTarget Targets="_BuildAndInvokeTestingPlatform" Condition=" '$(TargetFrameworks)' == '' "/>
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!-- Override VSTest target for single tfm -->
|
|
|
|
|
<Target Name="_BuildAndInvokeTestingPlatform" >
|
|
|
|
|
<!--
|
|
|
|
|
When the project is not built, build it. dotnet/sdk will call us always with this property set to true.
|
|
|
|
|
This is only needed for direct call to this target, e.g. dotnet build -t:vstest.
|
|
|
|
|
-->
|
|
|
|
|
<MSBuild Condition="'$(VSTestNoBuild)' != 'true'" Projects="$(MSBuildProjectFullPath)" />
|
|
|
|
|
<CallTarget Targets="InvokeTestingPlatform" />
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<!-- Invoke the tool task -->
|
|
|
|
|
<PropertyGroup>
|
|
|
|
|
<!--
|
|
|
|
|
The architecture below is used for log name, but it does not impact the architecture of the exe we will start.
|
|
|
|
|
We are basically trying to guess what we've just built and what architecture it has.
|
|
|
|
|
-->
|
|
|
|
|
<_TestArchitecture>$(PlatformTarget)</_TestArchitecture>
|
|
|
|
|
<!--
|
|
|
|
|
DefaultAppHostRuntimeIdentifier will tell us what is the architecture of the apphost
|
|
|
|
|
SDK runtime will build when not overridden. This takes TargetFramework into account so it is more accurate. This value depends on the actual architecture of the SDK, e.g. win-x64, or win-arm64.
|
|
|
|
|
-->
|
|
|
|
|
<_TestArchitecture Condition="('$(_TestArchitecture)' == '' or '$(_TestArchitecture)' == 'AnyCpu') and '$(DefaultAppHostRuntimeIdentifier)' != ''">$([System.Text.RegularExpressions.Regex]::Replace($(DefaultAppHostRuntimeIdentifier), '.*-', ''))</_TestArchitecture>
|
|
|
|
|
<!--
|
|
|
|
|
NETCoreSdkRuntimeIdentifier is used by DefaultAppHostRuntimeIdentifier to figure out the architecture, and is defined also for .NET Framework.
|
|
|
|
|
-->
|
|
|
|
|
<_TestArchitecture Condition="('$(_TestArchitecture)' == '' or '$(_TestArchitecture)' == 'AnyCpu') and '$(NETCoreSdkRuntimeIdentifier)' != ''">$([System.Text.RegularExpressions.Regex]::Replace($(NETCoreSdkRuntimeIdentifier), '.*-', ''))</_TestArchitecture>
|
|
|
|
|
<!-- If everyting else fails, fallback to x64. -->
|
|
|
|
|
<_TestArchitecture Condition="'$(_TestArchitecture)' == '' or '$(_TestArchitecture)' == 'AnyCpu'">x64</_TestArchitecture>
|
|
|
|
|
<TestingPlatformShowTestsFailure Condition=" '$(TestingPlatformShowTestsFailure)' == '' ">False</TestingPlatformShowTestsFailure>
|
|
|
|
|
<TestingPlatformCaptureOutput Condition=" '$(TestingPlatformCaptureOutput)' == '' " >true</TestingPlatformCaptureOutput>
|
|
|
|
|
</PropertyGroup>
|
|
|
|
|
<Target Name="InvokeTestingPlatform" >
|
|
|
|
|
<!--
|
|
|
|
|
This target name is hardcoded in TerminalLogger to mean start of test workload.
|
|
|
|
|
This let's terminal logger know that it should show `Testing` in the output,
|
|
|
|
|
and not the additional internal details, such as target names.
|
|
|
|
|
-->
|
|
|
|
|
<!-- Passing UseAppHost, IsExecutable, TargetDir, AssemblyName, and _NativeExecutableExtensions is mostly workaround -->
|
|
|
|
|
<!-- until we implement https://github.com/microsoft/testfx/issues/5091 properly -->
|
|
|
|
|
<!-- For now, we construct the correct "RunCommand" via these properties for a specific scenario that's known to be broken -->
|
|
|
|
|
<CallTarget Targets="_TestRunStart" />
|
|
|
|
|
<InvokeTestingPlatformTask TargetPath="$(TargetPath)"
|
|
|
|
|
UseAppHost="$(UseAppHost)"
|
|
|
|
|
IsExecutable="$(_IsExecutable)"
|
|
|
|
|
TargetDir="$(TargetDir)"
|
|
|
|
|
AssemblyName="$(AssemblyName)"
|
|
|
|
|
NativeExecutableExtension="$(_NativeExecutableExtension)"
|
|
|
|
|
TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)"
|
|
|
|
|
TargetFramework="$(TargetFramework)"
|
|
|
|
|
TestArchitecture="$(_TestArchitecture)"
|
|
|
|
|
ProjectFullPath="$(MSBuildProjectFullPath)"
|
|
|
|
|
TestingPlatformShowTestsFailure="$(TestingPlatformShowTestsFailure)"
|
|
|
|
|
TestingPlatformCommandLineArguments="$(TestingPlatformCommandLineArguments)"
|
|
|
|
|
VSTestCLIRunSettings="$(VSTestCLIRunSettings)"
|
|
|
|
|
TestingPlatformCaptureOutput="$(TestingPlatformCaptureOutput)"
|
|
|
|
|
DotnetHostPath="$(DOTNET_HOST_PATH)" />
|
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
|
|
<Target Name="_TestRunStart" />
|
|
|
|
|
|
|
|
|
|
<Target Name="_SetTestingPlatformDefaultsForContainerBuild" BeforeTargets="ComputeContainerConfig"
|
|
|
|
|
Condition="'$(IsPublishable)' == 'true' AND '$(EnableSdkContainerSupport)' == 'true' AND !$(RuntimeIdentifier.StartsWith('win'))">
|
|
|
|
|
<!--
|
|
|
|
|
When PublishContainer target is used to create a docker image for the test project, it will try to write /app/TestResults folder
|
|
|
|
|
which is a non-writable folder. The environment variable below (notice double underscore) is used to override option defaults, and is picked up
|
|
|
|
|
EnvironmentVariablesConfigurationProvider.
|
|
|
|
|
|
|
|
|
|
ComputeContainerConfig is target that PublishContainer depends on to figure out the configuration for the container.
|
|
|
|
|
-->
|
|
|
|
|
<ItemGroup>
|
|
|
|
|
<ContainerEnvironmentVariable Include="platformOptions__resultDirectory" Value="/tmp/TestResults"></ContainerEnvironmentVariable>
|
|
|
|
|
</ItemGroup>
|
|
|
|
|
</Target>
|
|
|
|
|
</Project>
|