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

Harden handling when getting the installed dotnet cli version #1367

Merged
merged 1 commit into from
Nov 13, 2019
Merged
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
9 changes: 7 additions & 2 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ function Get-InstalledCLIVersion {
# earlier versions of dotnet do not support --list-sdks, so we'll check the output
# and use dotnet --version as a fallback
$sdkList = & $script:DotnetExe --list-sdks 2>&1
$sdkList = "Unknown option"
if ( $sdkList -match "Unknown option" ) {
$installedVersions = & $script:DotnetExe --version 2>$null
}
Expand Down Expand Up @@ -618,9 +617,15 @@ function Get-DotnetExe
# it's possible that there are multiples. Take the highest version we find
# the problem is that invoking dotnet on a version which is lower than the specified
# version in global.json will produce an error, so we can only take the dotnet which executes
#
# dotnet --version has changed its output, so we have to work much harder to determine what's installed.
# dotnet --version can now emit a list of installed sdks as output *and* an error if the global.json
# file points to a version of the sdk which is *not* installed. However, the format of the new list
# with --version has a couple of spaces at the beginning of the line, so we need to be resilient
# against that.
$latestDotnet = $discoveredDotNet |
Where-Object { try { & $_ --version 2>$null } catch { } } |
Sort-Object { $pv = ConvertTo-PortableVersion (& $_ --version 2>$null); "$pv" } |
Sort-Object { $pv = ConvertTo-PortableVersion (& $_ --version 2>$null| %{$_.Trim().Split()[0]}); "$pv" } |
Select-Object -Last 1
if ( $latestDotnet ) {
$script:DotnetExe = $latestDotnet
Expand Down