Created
April 23, 2019 11:38
-
-
Save JeremySkinner/85224cc34d6af53e8472cc1c6097f321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From the FV buil script: | |
target install-dotnet-core { | |
# Version check as $IsWindows, $IsLinux etc are not defined in PS 5, only PS Core. | |
$win = (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) | |
$json = ConvertFrom-Json (Get-Content "$path/global.json" -Raw) | |
$required_version = $json.sdk.version | |
# If there's a version mismatch with what's defined in global.json then a | |
# call to dotnet --version will generate an error. AppVeyor vs local seem to have different | |
# behaviours handling exit codes (appveyor will immediately halt execution on windows, but not linux) | |
# so the simplest workaround is to write the output to a file and read it back rathre than rely on exit codes. | |
try { dotnet --version 2>&1>$null } catch { $install_sdk = $true } | |
if ($global:LASTEXITCODE) { | |
$install_sdk = $true; | |
$global:LASTEXITCODE = 0; | |
} | |
if ($install_sdk) { | |
$installer = $null; | |
if ($win) { | |
$installer = "$path/dotnet-installer.ps1" | |
(New-Object System.Net.WebClient).DownloadFile("https://dot.net/v1/dotnet-install.ps1", $installer); | |
} | |
else { | |
$installer = "$path/dotnet-installer" | |
(New-Object System.Net.WebClient).DownloadFile("https://dot.net/v1/dotnet-install.sh", $installer); | |
chmod +x dotnet-installer | |
} | |
# Extract the channel from the minimum required version. | |
$bits = $json.sdk.version.split(".") | |
$channel = $bits[0] + "." + $bits[1]; | |
Write-Host Installing $json.sdk.version from $channel | |
. $installer -i "$path/.dotnetsdk" -c $channel -v $json.sdk.version | |
# Collect installed SDKs. | |
$sdks = & "$path/.dotnetsdk/dotnet" --list-sdks | ForEach-Object { | |
$version = $_.Split(" ")[0].Split(".") | |
$version[0] + "." + $version[1]; | |
} | |
# Install any other SDKs required. Only bother installing if not installed already. | |
$json.others.PSObject.Properties | Foreach-Object { | |
if (!($sdks -contains $_.Name)) { | |
Write-Host Installing $_.Value from $_.Name | |
. $installer -i "$path/.dotnetsdk" -c $_.Name -v $_.Value | |
} | |
} | |
} | |
} | |
target find-sdk { | |
if (Test-Path "$path/.dotnetsdk") { | |
Write-Host "Using .NET SDK from $path/.dotnetsdk" | |
$env:DOTNET_INSTALL_DIR = "$path/.dotnetsdk" | |
if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) { | |
$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH" | |
} | |
else { | |
# Linux uses colon not semicolon, so can't use string interpolation | |
$env:PATH = $env:DOTNET_INSTALL_DIR + ":" + $env:PATH | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment