Skip to content

Commit

Permalink
(chocolatey#3327) Improves UX of Chocolatey Install without 4.8
Browse files Browse the repository at this point in the history
This commit introduces the idea that the dotnet installation needing a reboot should not immediately halt the Chocolatey installation, but instead proceed as far as possible - then prompt for a reboot.
  • Loading branch information
JPRuskin committed Apr 24, 2024
1 parent 3063450 commit 5d3172d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function Initialize-Chocolatey {
$installModule = Join-Path $thisScriptFolder 'chocolateyInstall\helpers\chocolateyInstaller.psm1'
Import-Module $installModule -Force

Install-DotNet48IfMissing
Install-DotNet48IfMissing

if ($chocolateyPath -eq '') {
$programData = [Environment]::GetFolderPath("CommonApplicationData")
Expand Down Expand Up @@ -204,13 +204,20 @@ Creating Chocolatey folders if they do not already exist.
$env:ChocolateyExitCode = 0
}

@"
if ($script:DotNetInstallRequiredReboot) {
@"
Chocolatey (choco.exe) is nearly ready.
You need to restart this machine prior to using choco.
"@ | Write-Output
} else {
@"
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
"@ | Write-Output
}

if (-not $allowInsecureRootInstall) {
Remove-OldChocolateyInstall $defaultChocolateyPathOld
Expand Down Expand Up @@ -812,9 +819,9 @@ function Install-DotNet48IfMissing {
$s = [System.Diagnostics.Process]::Start($psi);
$s.WaitForExit();
if ($s.ExitCode -eq 1641 -or $s.ExitCode -eq 3010) {
throw ".NET Framework 4.8 was installed, but a reboot is required. `n Please reboot the system and try to install/upgrade Chocolatey again."
}
if ($s.ExitCode -ne 0) {
Write-Warning ".NET Framework 4.8 was installed, but a reboot is required before using Chocolatey."
$script:DotNetInstallRequiredReboot = $true
} elseif ($s.ExitCode -ne 0) {
if ($netFx48InstallTries -ge 2) {
Write-ChocolateyError ".NET Framework install failed with exit code `'$($s.ExitCode)`'. `n This will cause the rest of the install to fail."
throw "Error installing .NET Framework 4.8 (exit code $($s.ExitCode)). `n Please install the .NET Framework 4.8 manually and reboot the system `n and then try to install/upgrade Chocolatey again. `n Download at `'$NetFx48Url`'"
Expand All @@ -832,11 +839,11 @@ function Invoke-Chocolatey-Initial {
try {
$chocoInstallationFolder = Get-ChocolateyInstallFolder
$chocoExe = Join-Path -Path $chocoInstallationFolder -ChildPath "choco.exe"
& $chocoExe -v | Out-Null
$runResult = & $chocoExe -v
Write-Debug "Chocolatey execution completed successfully."
}
catch {
Write-ChocolateyWarning "Unable to run Chocolatey at this time. It is likely that .Net Framework installation requires a system reboot"
Write-ChocolateyWarning "Unable to run Chocolatey at this time:`n$($runResult)"
}
}

Expand Down

0 comments on commit 5d3172d

Please sign in to comment.