install_dotnet_sdk.ps1 861 B

123456789101112131415161718192021
  1. #!/usr/bin/env powershell
  2. # Install dotnet SDK based on the SDK version from global.json
  3. Set-StrictMode -Version 2
  4. $ErrorActionPreference = 'Stop'
  5. # avoid "Unknown error on a send" in Invoke-WebRequest
  6. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  7. $InstallScriptUrl = 'https://dot.net/v1/dotnet-install.ps1'
  8. $InstallScriptPath = Join-Path "$env:TEMP" 'dotnet-install.ps1'
  9. $GlobalJsonPath = Join-Path $PSScriptRoot '..' | Join-Path -ChildPath 'global.json'
  10. # Resolve SDK version from global.json file
  11. $GlobalJson = Get-Content -Raw $GlobalJsonPath | ConvertFrom-Json
  12. $SDKVersion = $GlobalJson.sdk.version
  13. # Download install script
  14. Write-Host "Downloading install script: $InstallScriptUrl => $InstallScriptPath"
  15. Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath
  16. &$InstallScriptPath -Version $SDKVersion