@@ -34,7 +34,7 @@ if ($PSVersionTable.PSEdition -ne "Core") {
3434
3535task SetupDotNet - Before Clean , Build, TestHost, TestServer, TestProtocol, TestPowerShellApi {
3636
37- $minRequiredSdkVersion = " 2.0.0 "
37+ $minRequiredSdkVersion = ( Get-Content ( Join-Path $PSScriptRoot ' global.json ' ) | ConvertFrom-Json ).sdk.version
3838
3939 $dotnetPath = " $PSScriptRoot /.dotnet"
4040 $dotnetExePath = if ($script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
@@ -52,13 +52,8 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestP
5252
5353 # Make sure the dotnet we found is the right version
5454 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 ) {
6257 $script :dotnetExe = $dotnetExePath
6358 }
6459 else {
@@ -80,7 +75,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestP
8075
8176 # Download the official installation script and run it
8277 $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
8479 $env: DOTNET_INSTALL_DIR = " $PSScriptRoot /.dotnet"
8580
8681 if (! $script :IsUnix ) {
0 commit comments