Skip to content

Commit

Permalink
Allow VSTestConsole path to be specified (#325)
Browse files Browse the repository at this point in the history
Also moves the tasks dll to netstandard.library to improve our ability to merge dependencies
  • Loading branch information
Piotr Puszkiewicz authored and codito committed Jan 10, 2017
1 parent fd4207b commit 46c8ef2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- 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>
<VSTestConsoleFile Condition="$(VSTestConsoleFile) == ''">vstest.console.dll</VSTestConsoleFile>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
Expand Down Expand Up @@ -40,6 +41,7 @@ Copyright (c) .NET Foundation. All rights reserved.
VSTestListTests="$(VSTestListTests)"
VSTestDiag="$(VSTestDiag)"
VSTestCLIRunSettings="$(VSTestCLIRunSettings)"
VSTestConsolePath="$(VSTestConsoleFile)"
/>
</Target>

Expand Down
10 changes: 2 additions & 8 deletions src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ namespace Microsoft.TestPlatform.Build.Tasks
public class VSTestForwardingApp
{
private const string hostExe = "dotnet";
private const string vsTestAppName = "vstest.console.dll";
private readonly List<string> allArgs = new List<string>();
private int activeProcessId;

public VSTestForwardingApp(IEnumerable<string> argsToForward)
public VSTestForwardingApp(string vsTestExePath, IEnumerable<string> argsToForward)
{
this.allArgs.Add("exec");

// Ensure that path to vstest.console is whitespace friendly. User may install
// dotnet-cli to any folder containing whitespace (e.g. VS installs to program files).
// Arguments are already whitespace friendly.
this.allArgs.Add("\"" + GetVSTestExePath() + "\"");
this.allArgs.Add("\"" + vsTestExePath + "\"");
this.allArgs.AddRange(argsToForward);
}

Expand Down Expand Up @@ -69,10 +68,5 @@ public void Cancel()
Tracing.Trace(string.Format("VSTest: Killing process throws ArgumentException with the following message {0}. It may be that process is not running", ex.Message));
}
}

private static string GetVSTestExePath()
{
return Path.Combine(AppContext.BaseDirectory, vsTestAppName);
}
}
}
11 changes: 10 additions & 1 deletion src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class VSTestTask : Task, ICancelableTask
// The process which is invoking vstest.console
private VSTestForwardingApp vsTestForwardingApp;

private const string vsTestAppName = "vstest.console.dll";

public string TestFileFullPath
{
get;
Expand Down Expand Up @@ -77,12 +79,19 @@ public string[] VSTestCLIRunSettings
set;
}

[Required]
public string VSTestConsolePath
{
get;
set;
}

public override bool Execute()
{
var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE");
Tracing.traceEnabled = !string.IsNullOrEmpty(traceEnabledValue) && traceEnabledValue.Equals("1", StringComparison.OrdinalIgnoreCase);

vsTestForwardingApp = new VSTestForwardingApp(this.CreateArgument());
vsTestForwardingApp = new VSTestForwardingApp(this.VSTestConsolePath, this.CreateArgument());
if (!string.IsNullOrEmpty(this.VSTestFramework))
{
Console.WriteLine("Test run for {0}({1})", this.TestFileFullPath, this.VSTestFramework);
Expand Down

0 comments on commit 46c8ef2

Please sign in to comment.