@@ -34,7 +34,7 @@ if ($PSVersionTable.PSEdition -ne "Core") {
34
34
35
35
task SetupDotNet - Before Clean , Build, TestHost, TestServer, TestProtocol, TestPowerShellApi {
36
36
37
- $minRequiredSdkVersion = " 2.0.0 "
37
+ $minRequiredSdkVersion = ( Get-Content ( Join-Path $PSScriptRoot ' global.json ' ) | ConvertFrom-Json ).sdk.version
38
38
39
39
$dotnetPath = " $PSScriptRoot /.dotnet"
40
40
$dotnetExePath = if ($script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
@@ -52,13 +52,8 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestP
52
52
53
53
# Make sure the dotnet we found is the right version
54
54
if ($dotnetExePath ) {
55
- # dotnet --version can return a semver that System.Version can't handle
56
- # e.g.: 2.1.300-preview-01. The replace operator is used to remove any build suffix.
57
- $version = [version ]((& $dotnetExePath -- version) -replace ' [+-].*$' , ' ' )
58
- $maxRequiredSdkVersion = [version ]::Parse(" 3.0.0" )
59
-
60
- # $minRequiredSdkVersion <= version < $maxRequiredSdkVersion
61
- if ($version -ge [version ]$minRequiredSdkVersion -and $version -lt $maxRequiredSdkVersion ) {
55
+ # dotnet --version can write to stderr, which causes builds to abort, therefore use --list-sdks instead
56
+ if ((& $dotnetExePath -- list- sdks | ForEach-Object { $_.Split ()[0 ] }) -contains $requiredSdkVersion ) {
62
57
$script :dotnetExe = $dotnetExePath
63
58
}
64
59
else {
@@ -80,7 +75,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestP
80
75
81
76
# Download the official installation script and run it
82
77
$installScriptPath = " $ ( [System.IO.Path ]::GetTempPath()) dotnet-install.$installScriptExt "
83
- Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/v2.0.0/scripts/obtain /dotnet-install.$installScriptExt " - OutFile $installScriptPath
78
+ Invoke-WebRequest " https://dot.net/v1 /dotnet-install.$installScriptExt " - OutFile $installScriptPath
84
79
$env: DOTNET_INSTALL_DIR = " $PSScriptRoot /.dotnet"
85
80
86
81
if (! $script :IsUnix ) {
0 commit comments