From 46c8ef2530fe22b5b8f8a7f5ede8a8ed51e4a379 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Tue, 10 Jan 2017 02:36:07 -0800 Subject: [PATCH] Allow VSTestConsole path to be specified (#325) Also moves the tasks dll to netstandard.library to improve our ability to merge dependencies --- .../Microsoft.TestPlatform.targets | 2 ++ .../Tasks/VSTestForwardingApp.cs | 10 ++-------- src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs | 11 ++++++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets b/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets index 86ff8004c3..155892ede9 100644 --- a/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets +++ b/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets @@ -13,6 +13,7 @@ Copyright (c) .NET Foundation. All rights reserved. Microsoft.TestPlatform.Build.dll + vstest.console.dll $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -40,6 +41,7 @@ Copyright (c) .NET Foundation. All rights reserved. VSTestListTests="$(VSTestListTests)" VSTestDiag="$(VSTestDiag)" VSTestCLIRunSettings="$(VSTestCLIRunSettings)" + VSTestConsolePath="$(VSTestConsoleFile)" /> diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs index 47bac18237..d8a0c99486 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs @@ -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 allArgs = new List(); private int activeProcessId; - public VSTestForwardingApp(IEnumerable argsToForward) + public VSTestForwardingApp(string vsTestExePath, IEnumerable 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); } @@ -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); - } } } diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index 29bb2f7112..ef5c9d40e8 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -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; @@ -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);