Skip to content

Commit

Permalink
Create a proper MSBuild ToolTask based VSTestTask (#680)
Browse files Browse the repository at this point in the history
If the $(VSTestUseConsole) property is set to True during the build, the old console forwarding VSTestForwardTask is used.
  • Loading branch information
mcartoixa committed Apr 22, 2022
1 parent cd2b63e commit d1e30d4
Show file tree
Hide file tree
Showing 11 changed files with 709 additions and 838 deletions.
102 changes: 0 additions & 102 deletions src/Microsoft.TestPlatform.Build/ArgumentEscaper.cs

This file was deleted.

113 changes: 82 additions & 31 deletions src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ Copyright (c) .NET Foundation. All rights reserved.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Load Microsoft.TestPlatform.Build.Tasks.dll, this can be overridden to use a different version with $(VSTestTaskAssemblyFile) -->
<PropertyGroup>
<VSTestTaskAssemblyFile Condition="$(VSTestTaskAssemblyFile) == ''">Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile>
<VSTestConsolePath Condition="$(VSTestConsolePath) == ''">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory),"vstest.console.dll"))</VSTestConsolePath>
<VSTestTaskAssemblyFile Condition="'$(VSTestTaskAssemblyFile)' == ''">Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile>
<VSTestConsolePath Condition="'$(VSTestConsolePath)' == ''">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory),"vstest.console.dll"))</VSTestConsolePath>
<VSTestUseConsole Condition="'$(VSTestUseConsole)' == ''">False</VSTestUseConsole>
<VSTestNoBuild Condition="'$(VSTestNoBuild)' == ''">False</VSTestNoBuild>
<_VSTestMSBuildDependsOn Condition="$(_VSTestMSBuildDependsOn) == '' And !$(VSTestNoBuild)">$(MSBuildProjectDefaultTargets)</_VSTestMSBuildDependsOn>
</PropertyGroup>
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />

<!--
Expand All @@ -24,12 +28,61 @@ Copyright (c) .NET Foundation. All rights reserved.
Main entry point for running tests through vstest.console.exe
============================================================
-->
<Target Name="VSTest" DependsOnTargets="ShowInfoMessageIfProjectHasNoIsTestProjectProperty">
<Target
Name="VSTest"
DependsOnTargets="ShowInfoMessageIfProjectHasNoIsTestProjectProperty"
>
<!-- Unloggable but colorized output (cf. https://github.com/microsoft/vstest/issues/680) -->
<CallTarget Targets="_VSTestConsole" Condition="$(VSTestUseConsole)" />
<!-- Proper MSBuild integration, but no custom colorization -->
<CallTarget Targets="_VSTestMSBuild" Condition="!$(VSTestUseConsole)" />
</Target>

<!-- Used when called from dotnet msbuild command line: uses MSBuild logs but does not allow for console colorization -->
<Target
Name="_VSTestMSBuild"
DependsOnTargets="$(_VSTestMSBuildDependsOn)"
Condition="'$(IsTestProject)' == 'true'"
>
<Microsoft.TestPlatform.Build.Tasks.VSTestTask
TestFileFullPath="$(TargetPath)"
VSTestSetting="$([MSBuild]::ValueOrDefault($(VSTestSetting), '$(RunSettingsFilePath)'))"
VSTestTestAdapterPath="$(VSTestTestAdapterPath)"
VSTestFramework="$(TargetFrameworkMoniker)"
VSTestPlatform="$(PlatformTarget)"
VSTestTestCaseFilter="$(VSTestTestCaseFilter)"
VSTestLogger="$(VSTestLogger)"
VSTestListTests="$(VSTestListTests)"
VSTestDiag="$(VSTestDiag)"
VSTestCLIRunSettings="$(VSTestCLIRunSettings)"
VSTestConsolePath="$(VSTestConsolePath)"
VSTestResultsDirectory="$(VSTestResultsDirectory)"
VSTestVerbosity="$(VSTestVerbosity)"
VSTestCollect="$(VSTestCollect)"
VSTestBlame="$(VSTestBlame)"
VSTestBlameCrash="$(VSTestBlameCrash)"
VSTestBlameCrashDumpType="$(VSTestBlameCrashDumpType)"
VSTestBlameCrashCollectAlways="$(VSTestBlameCrashCollectAlways)"
VSTestBlameHang="$(VSTestBlameHang)"
VSTestBlameHangDumpType="$(VSTestBlameHangDumpType)"
VSTestBlameHangTimeout="$(VSTestBlameHangTimeout)"
VSTestTraceDataCollectorDirectoryPath="$(TraceDataCollectorDirectoryPath)"
VSTestArtifactsProcessingMode="$(VSTestArtifactsProcessingMode)"
VSTestSessionCorrelationId="$(VSTestSessionCorrelationId)"
VSTestNoLogo="$(VSTestNoLogo)"
/>
</Target>

<!-- Used when called from dotnet test command line: does not use MSBuild logs to allow for console colorization -->
<Target
Name="_VSTestConsole"
Condition="'$(IsTestProject)' == 'true'"
>
<CallTarget Condition="'$(VSTestNoBuild)' != 'true' AND '$(IsTestProject)' == 'true'" Targets="BuildProject" />

<CallTarget Targets="ShowCallOfVSTestTaskWithParameter" />

<Microsoft.TestPlatform.Build.Tasks.VSTestTask
<Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask
TestFileFullPath="$(TargetPath)"
VSTestSetting="$([MSBuild]::ValueOrDefault($(VSTestSetting), '$(RunSettingsFilePath)'))"
VSTestTestAdapterPath="$(VSTestTestAdapterPath)"
Expand All @@ -55,7 +108,6 @@ Copyright (c) .NET Foundation. All rights reserved.
VSTestArtifactsProcessingMode="$(VSTestArtifactsProcessingMode)"
VSTestSessionCorrelationId="$(VSTestSessionCorrelationId)"
VSTestNoLogo="$(VSTestNoLogo)"
Condition="'$(IsTestProject)' == 'true'"
/>
</Target>

Expand All @@ -70,37 +122,36 @@ Copyright (c) .NET Foundation. All rights reserved.
<MSBuild Projects ="$(MSBuildProjectFullPath)" />
<Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask LogType="BuildCompleted" />

<Message Text="Done Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" Importance="low" />
<Message Text="Done Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" Importance="Low" />
</Target>

<Target Name="ShowMsbuildWithParameter">
<Message Text="Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" Importance="low"/>
<Message Text="Value passed to msbuild are..." Importance="low" />
<Message Text="Configuration = $(Configuration)" Importance="low" />
<Message Text="TargetFramework = $(TargetFramework)" Importance="low" />
<Message Text="Platform = $(PlatformTarget)" Importance="low" />
<Message Text="OutputPath = $(OutputPath)" Importance="low" />
<Message Text="Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" Importance="Low"/>
<Message Text="Value passed to msbuild are..." Importance="Low" />
<Message Text="Configuration = $(Configuration)" Importance="Low" />
<Message Text="TargetFramework = $(TargetFramework)" Importance="Low" />
<Message Text="Platform = $(PlatformTarget)" Importance="Low" />
<Message Text="OutputPath = $(OutputPath)" Importance="Low" />
</Target>

<Target Name="ShowCallOfVSTestTaskWithParameter">
<Message Text="Calling task Microsoft.TestPlatform.Build.Tasks.VSTestTask with following parameter..." Importance="low" />
<Message Text="TestFileFullPath = $(TargetPath)" Importance="low" />
<Message Text="VSTestSetting = $(VSTestSetting)" Importance="low" />
<Message Text="VSTestTestAdapterPath = $(VSTestTestAdapterPath)" Importance="low" />
<Message Text="VSTestFramework = $(TargetFrameworkMoniker)" Importance="low" />
<Message Text="VSTestPlatform = $(PlatformTarget)" Importance="low" />
<Message Text="VSTestTestCaseFilter = $(VSTestTestCaseFilter)" Importance="low" />
<Message Text="VSTestLogger = $(VSTestLogger)" Importance="low" />
<Message Text="Calling task Microsoft.TestPlatform.Build.Tasks.VSTestTask with following parameter..." Importance="Low" />
<Message Text="TestFileFullPath = $(TargetPath)" Importance="Low" />
<Message Text="VSTestSetting = $(VSTestSetting)" Importance="Low" />
<Message Text="VSTestTestAdapterPath = $(VSTestTestAdapterPath)" Importance="Low" />
<Message Text="VSTestFramework = $(TargetFrameworkMoniker)" Importance="Low" />
<Message Text="VSTestPlatform = $(PlatformTarget)" Importance="Low" />
<Message Text="VSTestTestCaseFilter = $(VSTestTestCaseFilter)" Importance="Low" />
<Message Text="VSTestLogger = $(VSTestLogger)" Importance="Low" />
<Message Text="VSTestListTests = $(VSTestListTests)" Importance="low" />
<Message Text="VSTestDiag = $(VSTestDiag)" Importance="low" />
<Message Text="VSTestCLIRunSettings = $(VSTestCLIRunSettings)" Importance="low" />
<Message Text="VSTestResultsDirectory = $(VSTestResultsDirectory)" Importance="low" />
<Message Text="VSTestConsolePath = $(VSTestConsolePath)" Importance="low" />
<Message Text="VSTestVerbosity = $(VSTestVerbosity)" Importance="low" />
<Message Text="VSTestCollect = $(VSTestCollect)" Importance="low" />
<Message Text="VSTestBlame = $(VSTestBlame)" Importance="low" />
<Message Text="VSTestTraceDataCollectorDirectoryPath = $(TraceDataCollectorDirectoryPath)" Importance="low" />
<Message Text="VSTestNoLogo = $(VSTestNoLogo)" Importance="low" />
<Message Text="VSTestDiag = $(VSTestDiag)" Importance="Low" />
<Message Text="VSTestCLIRunSettings = $(VSTestCLIRunSettings)" Importance="Low" />
<Message Text="VSTestResultsDirectory = $(VSTestResultsDirectory)" Importance="Low" />
<Message Text="VSTestConsolePath = $(VSTestConsolePath)" Importance="Low" />
<Message Text="VSTestVerbosity = $(VSTestVerbosity)" Importance="Low" />
<Message Text="VSTestCollect = $(VSTestCollect)" Importance="Low" />
<Message Text="VSTestBlame = $(VSTestBlame)" Importance="Low" />
<Message Text="VSTestTraceDataCollectorDirectoryPath = $(TraceDataCollectorDirectoryPath)" Importance="Low" />
<Message Text="VSTestNoLogo = $(VSTestNoLogo)" Importance="Low" />
</Target>

</Project>
Loading

0 comments on commit d1e30d4

Please sign in to comment.