diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 0a59bad52..43fa11892 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -34,7 +34,7 @@ if ($PSVersionTable.PSEdition -ne "Core") { task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestPowerShellApi { - $minRequiredSdkVersion = "2.0.0" + $minRequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version $dotnetPath = "$PSScriptRoot/.dotnet" $dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" } @@ -52,13 +52,8 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestP # Make sure the dotnet we found is the right version if ($dotnetExePath) { - # dotnet --version can return a semver that System.Version can't handle - # e.g.: 2.1.300-preview-01. The replace operator is used to remove any build suffix. - $version = [version]((& $dotnetExePath --version) -replace '[+-].*$','') - $maxRequiredSdkVersion = [version]::Parse("3.0.0") - - # $minRequiredSdkVersion <= version < $maxRequiredSdkVersion - if ($version -ge [version]$minRequiredSdkVersion -and $version -lt $maxRequiredSdkVersion) { + # dotnet --version can write to stderr, which causes builds to abort, therefore use --list-sdks instead + if ((& $dotnetExePath --list-sdks | ForEach-Object { $_.Split()[0] }) -contains $requiredSdkVersion) { $script:dotnetExe = $dotnetExePath } else { @@ -80,7 +75,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestP # Download the official installation script and run it $installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt" - Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/v2.0.0/scripts/obtain/dotnet-install.$installScriptExt" -OutFile $installScriptPath + Invoke-WebRequest "https://dot.net/v1/dotnet-install.$installScriptExt" -OutFile $installScriptPath $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" if (!$script:IsUnix) { diff --git a/global.json b/global.json new file mode 100644 index 000000000..0c8476678 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "2.1.801" + } +}