Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow VSTestConsole path to be specified #325

Merged
merged 2 commits into from
Jan 10, 2017
Merged
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 @@ -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