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 Oct 24, 2021
1 parent d9e3ef5 commit 7acb932
Show file tree
Hide file tree
Showing 11 changed files with 619 additions and 777 deletions.
102 changes: 0 additions & 102 deletions src/Microsoft.TestPlatform.Build/ArgumentEscaper.cs

This file was deleted.

111 changes: 80 additions & 31 deletions src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets
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,59 @@ 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)"
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 @@ -53,7 +104,6 @@ Copyright (c) .NET Foundation. All rights reserved.
VSTestBlameHangTimeout="$(VSTestBlameHangTimeout)"
VSTestTraceDataCollectorDirectoryPath="$(TraceDataCollectorDirectoryPath)"
VSTestNoLogo="$(VSTestNoLogo)"
Condition="'$(IsTestProject)' == 'true'"
/>
</Target>

Expand All @@ -68,37 +118,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>
41 changes: 41 additions & 0 deletions src/Microsoft.TestPlatform.Build/Tasks/ITestTask.cs
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.TestPlatform.Build.Tasks
{

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

public interface ITestTask:
ITask,
ICancelableTask
{

ITaskItem TestFileFullPath { get; set; }
string VSTestSetting { get; set; }
ITaskItem[] VSTestTestAdapterPath { get; set; }
string VSTestFramework { get; set; }
string VSTestPlatform { get; set; }
string VSTestTestCaseFilter { get; set; }
string[] VSTestLogger { get; set; }
bool VSTestListTests { get; set; }
string VSTestDiag { get; set; }
string[] VSTestCLIRunSettings { get; set; }
ITaskItem VSTestConsolePath { get; set; }
ITaskItem VSTestResultsDirectory { get; set; }
string VSTestVerbosity { get; set; }
string[] VSTestCollect { get; set; }
bool VSTestBlame { get; set; }
bool VSTestBlameCrash { get; set; }
string VSTestBlameCrashDumpType { get; set; }
bool VSTestBlameCrashCollectAlways { get; set; }
bool VSTestBlameHang { get; set; }
string VSTestBlameHangDumpType { get; set; }
string VSTestBlameHangTimeout { get; set; }
ITaskItem VSTestTraceDataCollectorDirectoryPath { get; set; }
bool VSTestNoLogo { get; set; }

TaskLoggingHelper Log { get; }
}
}

0 comments on commit 7acb932

Please sign in to comment.