File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -502,13 +502,19 @@ function Get-DotnetExe
502
502
$discoveredDotnet = Get-Command - CommandType Application dotnet - ErrorAction SilentlyContinu
503
503
if ( $discoveredDotnet ) {
504
504
# it's possible that there are multiples. Take the highest version we find
505
- $latestDotnet = $discoveredDotNet | Sort-object { [version ](& $_ -- version) } | Select-Object - Last 1
506
- Write-Verbose - Verbose " Found dotnet here: $latestDotnet "
507
- $script :DotnetExe = $latestDotnet
508
- return $latestDotnet
509
- }
510
- # it's not in the path, try harder to find it
511
- # check the usual places
505
+ # the problem is that invoking dotnet on a version which is lower than the specified
506
+ # version in global.json will produce an error, so we can only take the dotnet which executes
507
+ $latestDotnet = $discoveredDotNet |
508
+ Where-Object { try { & $_ -- version } catch { } } |
509
+ Sort-Object { [version ](& $_ -- version) } |
510
+ Select-Object - Last 1
511
+ if ( $latestDotnet ) {
512
+ Write-Verbose - Verbose " Found dotnet here: $latestDotnet "
513
+ $script :DotnetExe = $latestDotnet
514
+ return $latestDotnet
515
+ }
516
+ }
517
+ # it's not in the path, try harder to find it by checking some usual places
512
518
if ( ! (test-path variable:IsWindows) -or $IsWindows ) {
513
519
$dotnetHuntPath = " $HOME \AppData\Local\Microsoft\dotnet\dotnet.exe"
514
520
Write-Verbose - Verbose " checking Windows $dotnetHuntPath "
You can’t perform that action at this time.
0 commit comments