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 Sep 20, 2023
1 parent 48ee5cf commit de86262
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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,7 +819,8 @@ 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."
Write-Warning ".NET Framework 4.8 was installed, but a reboot is required before using Chocolatey."
$script:DotNetInstallRequiredReboot = $true
}
if ($s.ExitCode -ne 0) {
if ($netFx48InstallTries -ge 2) {
Expand All @@ -832,11 +840,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 de86262

Please sign in to comment.