Skip to content

Commit

Permalink
Avoid unannounced system restart
Browse files Browse the repository at this point in the history
When installing the .NET SDK or runtime, if the installer wants a system restart, it would do so quietly. This avoids the restart but adds a prompt at the end of the script to inform the user of a restart being required when necessary.

Fixes #57
  • Loading branch information
AArnott committed Jun 15, 2020
1 parent 3c97ead commit bc3f88d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ $EnvVars = @{}
if (!$NoPrerequisites) {
& "$PSScriptRoot\tools\Install-NuGetCredProvider.ps1" -AccessToken $AccessToken -Force:$UpgradePrerequisites
& "$PSScriptRoot\tools\Install-DotNetSdk.ps1" -InstallLocality $InstallLocality
if ($LASTEXITCODE -eq 3010) {
Exit 3010
}

# The procdump tool and env var is required for dotnet test to collect hang/crash dumps of tests.
# But it only works on Windows.
Expand Down
14 changes: 12 additions & 2 deletions tools/Install-DotNetSdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ Function Install-DotNet($Version, [switch]$Runtime) {
Write-Host "Downloading .NET Core $sdkSubstring$Version..."
$Installer = Get-InstallerExe -Version $Version -Runtime:$Runtime
Write-Host "Installing .NET Core $sdkSubstring$Version..."
cmd /c start /wait $Installer /install /quiet
if ($LASTEXITCODE -ne 0) {
cmd /c start /wait $Installer /install /passive /norestart
if ($LASTEXITCODE -eq 3010) {
Write-Verbose "Restart required"
} elseif ($LASTEXITCODE -ne 0) {
throw "Failure to install .NET Core SDK"
}
}
Expand All @@ -95,16 +97,24 @@ if ($InstallLocality -eq 'machine') {
if ($IsMacOS -or $IsLinux) {
$DotNetInstallDir = '/usr/share/dotnet'
} else {
$restartRequired = $false
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
Install-DotNet -Version $sdkVersion
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
}

$runtimeVersions | Get-Unique |% {
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
Install-DotNet -Version $_ -Runtime
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
}
}

if ($restartRequired) {
Write-Host -ForegroundColor Yellow "System restart required"
Exit 3010
}

return
}
} elseif ($InstallLocality -eq 'repo') {
Expand Down

0 comments on commit bc3f88d

Please sign in to comment.