Skip to content
Open
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
Expand Up @@ -15,6 +15,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<VSTestTaskAssemblyFile Condition="$(VSTestTaskAssemblyFile) == ''">Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile>
<VSTestConsolePath Condition="$(VSTestConsolePath) == ''">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory),"vstest.console.dll"))</VSTestConsolePath>
<VSTestNoBuild Condition="'$(VSTestNoBuild)' == ''">False</VSTestNoBuild>
<!-- When terminal logger is active and user has not opted out, default to MSBuild output mode so
test output from parallel MSBuild nodes is not lost. Users can opt out with VsTestUseMSBuildOutput=false. -->
<VsTestUseMSBuildOutput Condition="'$(VsTestUseMSBuildOutput)' == '' AND '$(_MSBUILDTLENABLED)' == '1'">True</VsTestUseMSBuildOutput>
<VsTestUseMSBuildOutput Condition="'$(VsTestUseMSBuildOutput)' == ''">False</VsTestUseMSBuildOutput>
</PropertyGroup>
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
Expand All @@ -32,8 +35,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Fallback to this old view when terminal logger is not enabled (_MSBUILDTLENABLED==0) , or when user explicitly opts out (VsTestUseMSBuildOutput != true) -->
<CallTarget Targets="_VSTestConsole" Condition="$(_MSBUILDTLENABLED) == '0' OR !$(VsTestUseMSBuildOutput) OR $(MSBUILDENSURESTDOUTFORTASKPROCESSES) == '1'" />
<!-- Proper MSBuild integration, but no custom colorization -->
<!-- Use the new view whe terminal logger is enabled (_MSBUILDTLENABLED==0), and user did not opt out (VsTestUseMSBuildOutput == true) -->
<CallTarget Targets="_VSTestMSBuild" Condition="$(_MSBUILDTLENABLED) == '1' AND $(VsTestUseMSBuildOutput)" />
<!-- Use the new view when terminal logger is enabled (_MSBUILDTLENABLED==1), user did not opt out (VsTestUseMSBuildOutput == true),
and MSBUILDENSURESTDOUTFORTASKPROCESSES is not set (set by dotnet test, which uses the console path instead). -->
<CallTarget Targets="_VSTestMSBuild" Condition="$(_MSBUILDTLENABLED) == '1' AND $(VsTestUseMSBuildOutput) AND $(MSBUILDENSURESTDOUTFORTASKPROCESSES) != '1'" />
</Target>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,23 @@ public void MSBuildLoggerCanBeDisabledByEnvironmentVariableProperty(RunnerInfo r

ExitCodeEquals(1);
}

[TestMethod]
// patched dotnet is not published on non-windows systems
[TestCategory("Windows-Review")]
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false)]
public void MSBuildLoggerIsUsedAutomaticallyWithDotnetMSBuildWhenTerminalLoggerIsActive(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj", runnerInfo.TargetFramework);
// Invoke via dotnet msbuild /t:VSTest with terminal logger on and no explicit VsTestUseMSBuildOutput property.
// The MSBuild output path should be used automatically when the terminal logger is active.
InvokeDotnetMSBuildTest($@"-t:VSTest {projectPath} -tl:on -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));

StdOutputContains("TESTERROR");
StdOutputContains("FailingTest (");
ExitCodeEquals(1);
Comment on lines +94 to +100
}

}
14 changes: 14 additions & 0 deletions test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ public void InvokeDotnetTest(string arguments, Dictionary<string, string?>? envi
FormatStandardOutCome();
}

public void InvokeDotnetMSBuildTest(string arguments, Dictionary<string, string?>? environmentVariables = null, string? workingDirectory = null)
{
var debugEnvironmentVariables = AddDebugEnvironmentVariables(environmentVariables);

var vstestConsolePath = GetDotnetRunnerPath();
var consolePathParameter = $@" -p:VsTestConsolePath=""{vstestConsolePath}""";
arguments += consolePathParameter;

debugEnvironmentVariables["VSTEST_CONSOLE_PATH"] = vstestConsolePath;

IntegrationTestBase.ExecutePatchedDotnet("msbuild", arguments, out _standardTestOutput, out _standardTestError, out _runnerExitCode, debugEnvironmentVariables, workingDirectory);
FormatStandardOutCome();
}

/// <summary>
/// Invokes <c>vstest.console</c> to execute tests in a test assembly.
/// </summary>
Expand Down
Loading