-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathInstall-DotNetSdk.ps1
More file actions
64 lines (51 loc) · 1.87 KB
/
Install-DotNetSdk.ps1
File metadata and controls
64 lines (51 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env pwsh
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
<#
.SYNOPSIS
Install the .NET Core SDK at the specified path.
.PARAMETER InstallPath
The path where the .NET Core SDK is to be installed.
.PARAMETER Channel
The version of the .NET Core SDK to be installed.
#>
[cmdletbinding()]
param(
[string]
$InstallPath,
[string]
$Channel = "10.0"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
if (!(Test-Path "$InstallPath")) {
mkdir "$InstallPath" | Out-Null
}
$IsRunningOnUnix = $PSVersionTable.contains("Platform") -and $PSVersionTable.Platform -eq "Unix"
if ($IsRunningOnUnix) {
$DotnetInstallScript = "dotnet-install.sh"
}
else {
$DotnetInstallScript = "dotnet-install.ps1"
}
$DotnetInstallScriptPath = Join-Path -Path $InstallPath -ChildPath $DotnetInstallScript
if (!(Test-Path $DotnetInstallScriptPath)) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
& "$PSScriptRoot/Invoke-WithRetry.ps1" "Invoke-WebRequest 'https://builds.dotnet.microsoft.com/dotnet/scripts/v1/$DotnetInstallScript' -OutFile $DotnetInstallScriptPath"
}
$DotnetChannel = $Channel
$InstallFailed = $false
if ($IsRunningOnUnix) {
& chmod +x $DotnetInstallScriptPath
& "$PSScriptRoot/Invoke-WithRetry.ps1" "$DotnetInstallScriptPath --channel $DotnetChannel --install-dir $InstallPath" -Retries 5
$InstallFailed = ($LASTEXITCODE -ne 0)
}
else {
& "$PSScriptRoot/Invoke-WithRetry.ps1" "$DotnetInstallScriptPath -Channel $DotnetChannel -InstallDir $InstallPath" -Retries 5
$InstallFailed = (-not $?)
}
# See https://github.com/NuGet/NuGet.Client/pull/4259
$Env:NUGET_EXPERIMENTAL_CHAIN_BUILD_RETRY_POLICY = "6,1500"
if ($InstallFailed) { throw "Failed to install the .NET Core SDK" }