Skip to content

Commit 0e0b8be

Browse files
authored
Merge pull request #371 from AArnott/multipleSDKs
Add support for a repo to hard-code extra SDKs that must be installed
2 parents 508b839 + 8fe4f14 commit 0e0b8be

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

tools/Install-DotNetSdk.ps1

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ if (!(Test-Path $DotNetInstallScriptRoot)) { New-Item -ItemType Directory -Path
3636
$DotNetInstallScriptRoot = Resolve-Path $DotNetInstallScriptRoot
3737

3838
# Look up actual required .NET SDK version from global.json
39-
$sdkVersion = & "$PSScriptRoot/variables/DotNetSdkVersion.ps1"
39+
$sdks = @(New-Object PSObject -Property @{ Version = & "$PSScriptRoot/variables/DotNetSdkVersion.ps1" })
40+
41+
# Sometimes a repo requires extra SDKs to be installed (e.g. msbuild.locator scenarios running in tests).
42+
# In such a circumstance, a precise SDK version or a channel can be added as in the example below:
43+
# $sdks += New-Object PSObject -Property @{ Channel = '8.0' }
4044

4145
If ($IncludeX86 -and ($IsMacOS -or $IsLinux)) {
4246
Write-Verbose "Ignoring -IncludeX86 switch because 32-bit runtimes are only supported on Windows."
@@ -191,13 +195,16 @@ if ($InstallLocality -eq 'machine') {
191195
$DotNetInstallDir = '/usr/share/dotnet'
192196
} else {
193197
$restartRequired = $false
194-
if ($PSCmdlet.ShouldProcess(".NET SDK $sdkVersion", "Install")) {
195-
Install-DotNet -Version $sdkVersion -Architecture $arch
196-
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
197-
198-
if ($IncludeX86) {
199-
Install-DotNet -Version $sdkVersion -Architecture x86
198+
$sdks |% {
199+
if ($_.Version) { $version = $_.Version } else { $version = $_.Channel }
200+
if ($PSCmdlet.ShouldProcess(".NET SDK $_", "Install")) {
201+
Install-DotNet -Version $version -Architecture $arch
200202
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
203+
204+
if ($IncludeX86) {
205+
Install-DotNet -Version $version -Architecture x86
206+
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
207+
}
201208
}
202209
}
203210

@@ -296,29 +303,33 @@ $DotNetInstallScriptPathExpression = "& '$DotNetInstallScriptPathExpression'"
296303
$anythingInstalled = $false
297304
$global:LASTEXITCODE = 0
298305

299-
if ($PSCmdlet.ShouldProcess(".NET SDK $sdkVersion", "Install")) {
300-
$anythingInstalled = $true
301-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture $arch -InstallDir $DotNetInstallDir $switches"
306+
$sdks |% {
307+
if ($_.Version) { $parameters = '-Version', $_.Version } else { $parameters = '-Channel', $_.Channel }
302308

303-
if ($LASTEXITCODE -ne 0) {
304-
Write-Error ".NET SDK installation failure: $LASTEXITCODE"
305-
exit $LASTEXITCODE
306-
}
307-
} else {
308-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture $arch -InstallDir $DotNetInstallDir $switches -DryRun"
309-
}
310-
311-
if ($IncludeX86) {
312-
if ($PSCmdlet.ShouldProcess(".NET x86 SDK $sdkVersion", "Install")) {
309+
if ($PSCmdlet.ShouldProcess(".NET SDK $_", "Install")) {
313310
$anythingInstalled = $true
314-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture x86 -InstallDir $DotNetX86InstallDir $switches"
311+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture $arch -InstallDir $DotNetInstallDir $switches"
315312

316313
if ($LASTEXITCODE -ne 0) {
317-
Write-Error ".NET x86 SDK installation failure: $LASTEXITCODE"
314+
Write-Error ".NET SDK installation failure: $LASTEXITCODE"
318315
exit $LASTEXITCODE
319316
}
320317
} else {
321-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture x86 -InstallDir $DotNetX86InstallDir $switches -DryRun"
318+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture $arch -InstallDir $DotNetInstallDir $switches -DryRun"
319+
}
320+
321+
if ($IncludeX86) {
322+
if ($PSCmdlet.ShouldProcess(".NET x86 SDK $_", "Install")) {
323+
$anythingInstalled = $true
324+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture x86 -InstallDir $DotNetX86InstallDir $switches"
325+
326+
if ($LASTEXITCODE -ne 0) {
327+
Write-Error ".NET x86 SDK installation failure: $LASTEXITCODE"
328+
exit $LASTEXITCODE
329+
}
330+
} else {
331+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture x86 -InstallDir $DotNetX86InstallDir $switches -DryRun"
332+
}
322333
}
323334
}
324335

0 commit comments

Comments
 (0)