From 232de6668374e753552f18edc87b165da15d6348 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Wed, 14 Jun 2017 10:40:46 -0500 Subject: [PATCH] find_vstool now verifies that the tool can be executed This improvement is meant to discard tool binaries that cannot be run. This is useful when you have an old install of VS that is broken for whatever reason. Now, we will ensure the tool has a valid exit code --- Tools/find_vstool.ps1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Tools/find_vstool.ps1 b/Tools/find_vstool.ps1 index d476b69f..847e896b 100644 --- a/Tools/find_vstool.ps1 +++ b/Tools/find_vstool.ps1 @@ -27,6 +27,16 @@ function EditBinCertificateIsValid() { } } + +function ToolCanBeExecuted { + param ( + [string] + $Path + ) + $null = & $Path + Write-Output ($LASTEXITCODE -gt 0) +} + $rootSearchPaths = @( [System.IO.Directory]::EnumerateFileSystemEntries("C:\Program Files", "*Visual Studio*", [System.IO.SearchOption]::TopDirectoryOnly), [System.IO.Directory]::EnumerateFileSystemEntries("C:\Program Files (x86)", "*Visual Studio*", [System.IO.SearchOption]::TopDirectoryOnly) @@ -37,7 +47,7 @@ foreach ($searchPath in $rootSearchPaths) { foreach ($visualStudioFolder in $searchPath) { $matchingExes = [System.IO.Directory]::EnumerateFileSystemEntries($visualStudioFolder, $FileName, [System.IO.SearchOption]::AllDirectories) foreach ($matchingExe in $matchingExes) { - if (EditBinCertificateIsValid -Path $matchingExe) { + if ((EditBinCertificateIsValid -Path $matchingExe) -and (ToolCanBeExecuted -Path $matchingExe)) { return $matchingExe } }