From 787e8463c613bd279b4e682901449b188dc6b786 Mon Sep 17 00:00:00 2001 From: David Federman Date: Thu, 28 Mar 2024 16:58:01 -0700 Subject: [PATCH] RunVSTest: Allow overriding the ToolExe/ToolPath (#548) --- src/RunTests/RunVSTestTask.cs | 10 ++- .../build/Microsoft.Build.RunVSTest.props | 4 +- .../build/Microsoft.Build.RunVSTest.targets | 64 +++++++++---------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/RunTests/RunVSTestTask.cs b/src/RunTests/RunVSTestTask.cs index 7c36261..eb38991 100644 --- a/src/RunTests/RunVSTestTask.cs +++ b/src/RunTests/RunVSTestTask.cs @@ -139,7 +139,15 @@ public class RunVSTestTask : ToolTask /// protected override string GenerateFullPathToTool() { - return $@"{Environment.GetEnvironmentVariable("VSINSTALLDIR")}\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"; + // Attempt to look in the VS installation dir + string vsInstallDir = Environment.GetEnvironmentVariable("VSINSTALLDIR"); + if (!string.IsNullOrEmpty(vsInstallDir)) + { + return $@"{vsInstallDir}\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"; + } + + // Fallback to looking for the tool on the PATH + return ToolExe; } /// diff --git a/src/RunTests/build/Microsoft.Build.RunVSTest.props b/src/RunTests/build/Microsoft.Build.RunVSTest.props index 9d8b501..bd1fe62 100644 --- a/src/RunTests/build/Microsoft.Build.RunVSTest.props +++ b/src/RunTests/build/Microsoft.Build.RunVSTest.props @@ -4,8 +4,8 @@ Licensed under the MIT license. --> - + - true + true \ No newline at end of file diff --git a/src/RunTests/build/Microsoft.Build.RunVSTest.targets b/src/RunTests/build/Microsoft.Build.RunVSTest.targets index eeeeb29..e4ff39e 100644 --- a/src/RunTests/build/Microsoft.Build.RunVSTest.targets +++ b/src/RunTests/build/Microsoft.Build.RunVSTest.targets @@ -4,36 +4,36 @@ Licensed under the MIT license. --> - - - - - - - - + + + + + + + +