Skip to content

Commit

Permalink
install required .NET SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
cwe1ss committed Nov 11, 2020
1 parent ac28ff9 commit 6b65ef6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@ function Task {
}
}

Task "install-dotnet" $true {
$path = $PSScriptRoot

# Ensures that .net core is up to date.
# first get the required version from global.json
$json = ConvertFrom-Json (Get-Content "$path/global.json" -Raw)
$required_version = $json.sdk.version

# Running dotnet --version stupidly fails if the required SDK version is higher
# than the currently installed version. So move global.json out the way
# and then put it back again
Rename-Item "$path/global.json" "$path/global.json.bak"
$current_version = (dotnet --version)
Rename-Item "$path/global.json.bak" "$path/global.json"
Write-Host "Required .NET version: $required_version Installed: $current_version"

if ($current_version -lt $required_version) {
# Current installed version is too low.
# Install new version as a local only dependency.
$urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$required_version/dotnet-sdk-$required_version-win-x64.zip"
Write-Host "Installing .NET Core $required_version from $urlCurrent"
$env:DOTNET_INSTALL_DIR = "$path/.dotnetsdk"
New-Item -Type Directory $env:DOTNET_INSTALL_DIR -Force | Out-Null
(New-Object System.Net.WebClient).DownloadFile($urlCurrent, "dotnet.zip")
Write-Host "Unzipping to $env:DOTNET_INSTALL_DIR"
Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory("dotnet.zip", $env:DOTNET_INSTALL_DIR)
}
}


Task "Init" $true {

Expand Down

0 comments on commit 6b65ef6

Please sign in to comment.