Skip to content

Commit ee2843b

Browse files
committed
allow to install 2 sdks from powershell
1 parent 4237611 commit ee2843b

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

build.ps1

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ $DotNetChannel = 'LTS'
5757
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
5858

5959
[string] $CakeVersion = ''
60-
[string] $DotNetVersion= ''
60+
[string[]] $DotNetVersion= ''
6161
foreach($line in Get-Content (Join-Path $PSScriptRoot 'build.config'))
6262
{
6363
if ($line -like 'CAKE_VERSION=*') {
6464
$CakeVersion = $line.SubString(13)
6565
}
6666
elseif ($line -like 'DOTNET_VERSION=*') {
67-
$DotNetVersion =$line.SubString(15)
67+
$DotNetVersion = $line.SubString(15).Split(',')
6868
}
6969
}
7070

@@ -110,40 +110,50 @@ Function Remove-PathVariable([string]$VariableToRemove)
110110
}
111111
}
112112

113-
# Get .NET Core CLI path if installed.
114-
$FoundDotNetCliVersion = $null;
115-
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
116-
$FoundDotNetCliVersion = dotnet --version;
117-
}
118-
119-
if($FoundDotNetCliVersion -ne $DotNetVersion) {
120-
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
121-
if (!(Test-Path $InstallPath)) {
122-
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null;
113+
Function Add-PathVariable([string]$PathToAdd)
114+
{
115+
$SplitChar = ';'
116+
if ($IsMacOS -or $IsLinux) {
117+
$SplitChar = ':'
123118
}
124119

120+
$env:PATH = "$($PathToAdd)$($SplitChar)$env:PATH"
121+
}
122+
123+
Function Install-Dotnet($DotNetVersion)
124+
{
125125
if ($IsMacOS -or $IsLinux) {
126126
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
127127
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
128+
128129
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
129-
Remove-PathVariable "$InstallPath"
130-
$env:PATH = "$($InstallPath):$env:PATH"
131130
}
132131
else {
133132
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
134133
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
135-
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
136134

137-
Remove-PathVariable "$InstallPath"
138-
$env:PATH = "$InstallPath;$env:PATH"
135+
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
139136
}
140-
$env:DOTNET_ROOT=$InstallPath
141137
}
142138

139+
# Get .NET Core CLI path if installed.
140+
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
141+
if (!(Test-Path $InstallPath)) {
142+
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null;
143+
}
144+
145+
foreach($version in $DotNetVersion)
146+
{
147+
Install-Dotnet $version
148+
}
149+
150+
Remove-PathVariable "$InstallPath"
151+
Add-PathVariable "$InstallPath"
152+
$env:DOTNET_ROOT=$InstallPath
153+
143154
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
144155
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
145156

146-
147157
###########################################################################
148158
# INSTALL CAKE
149159
###########################################################################

0 commit comments

Comments
 (0)