2 $DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1';
3 $DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh'
4 $PSScriptRoot = Split-Path $MyInvocation.MyCommand
.Path
-Parent
6 # Make sure tools folder exists
7 $ToolPath = Join-Path $PSScriptRoot "tools"
8 if (!(Test-Path $ToolPath)) {
9 Write-Verbose "Creating tools directory..."
10 New-Item -Path
$ToolPath -Type Directory
-Force
| out-null
14 if ($PSVersionTable.PSEdition
-ne
'Core') {
15 # Attempt to set highest encryption available for SecurityProtocol.
16 # PowerShell will not set this by default (until maybe .NET 4.6.x). This
17 # will typically produce a message for PowerShell v2 (just an info
20 # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
21 # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
22 # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
23 # installed (.NET 4.5 is an in-place upgrade).
24 [System
.Net
.ServicePointManager
]::SecurityProtocol
= 3072 -bor
768 -bor
192 -bor
48
26 Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3'
30 ###########################################################################
31 # INSTALL .NET CORE CLI
32 ###########################################################################
34 $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE
=1
35 $env:DOTNET_CLI_TELEMETRY_OPTOUT
=1
36 $env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX
=2
39 Function Remove-PathVariable
([string
]$VariableToRemove)
42 if ($IsMacOS -or
$IsLinux) {
46 $path = [Environment
]::GetEnvironmentVariable
("PATH", "User")
49 $newItems = $path.Split
($SplitChar, [StringSplitOptions
]::RemoveEmptyEntries
) | Where-Object { "$($_)" -inotlike
$VariableToRemove }
50 [Environment
]::SetEnvironmentVariable
("PATH", [System
.String
]::Join
($SplitChar, $newItems), "User")
53 $path = [Environment
]::GetEnvironmentVariable
("PATH", "Process")
56 $newItems = $path.Split
($SplitChar, [StringSplitOptions
]::RemoveEmptyEntries
) | Where-Object { "$($_)" -inotlike
$VariableToRemove }
57 [Environment
]::SetEnvironmentVariable
("PATH", [System
.String
]::Join
($SplitChar, $newItems), "Process")
61 $InstallPath = Join-Path $PSScriptRoot ".dotnet"
62 $GlobalJsonPath = Join-Path $PSScriptRoot "global.json"
63 if (!(Test-Path $InstallPath)) {
64 New-Item -Path
$InstallPath -ItemType Directory
-Force
| Out-Null;
67 if ($IsMacOS -or
$IsLinux) {
68 $ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
69 (New-Object System
.Net
.WebClient
).DownloadFile
($DotNetUnixInstallerUri, $ScriptPath);
70 & bash
$ScriptPath --jsonfile
"$GlobalJsonPath" --install-dir
"$InstallPath" --no-path
72 Remove-PathVariable
"$InstallPath"
73 $env:PATH
= "$($InstallPath):$env:PATH"
76 $ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
77 (New-Object System
.Net
.WebClient
).DownloadFile
($DotNetInstallerUri, $ScriptPath);
78 & $ScriptPath -JSonFile
$GlobalJsonPath -InstallDir
$InstallPath;
80 Remove-PathVariable
"$InstallPath"
81 $env:PATH
= "$InstallPath;$env:PATH"
83 $env:DOTNET_ROOT
=$InstallPath
85 ###########################################################################
87 ###########################################################################
91 ###########################################################################
93 ###########################################################################
94 & dotnet cake
./build
.cake
$args