Use Remembered Arguments for a Package During Upgrades · Issue #797 · chocolatey/choco
Posted by jpluimers on 2024/03/06
I totally missed this feature got implemented: [Wayback/Archive] Use Remembered Arguments for a Package During Upgrades · Issue #797 · chocolatey/choco. I also seem to be lucky I have not tried it out yet (:
I bumped into it via [Wayback/Archive] Chocolatey Software | Notepad++ 8.4.4, which had this interesting comment:
If you want Notepad++ 32 bit and you want it to stay on 32 bit with upgrades, ensure you are on Chocolatey 0.10.4 (or newer). Then add `
-x86` to your installation arguments. Then turn on the remembered arguments feature with ‘choco feature enable -n useRememberedArgumentsForUpgrades‘ – this will ensure that `-x86` gets passed on upgrade when running `choco upgrade all`. For more information on how this works, see https://github.com/chocolat…797
First of all, if you started using Chocolatey at or before 0.14, the useRememberedArgumentsForUpgrades feature is disabled by default and kept that way even after upgrading to the most recent version. You can see executing choco feature list on a system that started with Chocolatey:
C:\temp>choco feature list Chocolatey v1.1.0 2 validations performed. 1 success(es), 1 warning(s), and 0 error(s). Validation Warnings: - A pending system reboot request has been detected, however, this is being ignored due to the current command being used 'feature'. It is recommended that you reboot at your earliest convenience. [x] checksumFiles - Checksum files when pulled in from internet (based on package). [x] autoUninstaller - Uninstall from programs and features without requiring an explicit uninstall script. [ ] allowGlobalConfirmation - Prompt for confirmation in scripts or bypass. [ ] failOnAutoUninstaller - Fail if automatic uninstaller fails. [ ] failOnStandardError - Fail if install provider writes to stderr. Not recommended for use. Available in 0.9.10+. [ ] allowEmptyChecksums - Allow packages to have empty/missing checksums for downloaded resources from non-secure locations (HTTP, FTP). Enabling is not recommended if using sources that download resources from the internet. Available in 0.10.0+. [x] allowEmptyChecksumsSecure - Allow packages to have empty/missing checksums for downloaded resources from secure locations (HTTPS). Available in 0.10.0+. [x] powershellHost - Use Chocolatey's built-in PowerShell host. Available in 0.9.10+. [ ] logEnvironmentValues - Log Environment Values - will log values of environment before and after install (could disclose sensitive data). Available in 0.9.10+. [ ] virusCheck - Virus Check - perform virus checking on downloaded files. Available in 0.9.10+. Licensed versions only. [ ] failOnInvalidOrMissingLicense - Fail On Invalid Or Missing License - allows knowing when a license is expired or not applied to a machine. Available in 0.9.10+. [x] ignoreInvalidOptionsSwitches - Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail? Available in 0.9.10+. [x] usePackageExitCodes - Use Package Exit Codes - Package scripts can provide exit codes. With this on, package exit codes will be what choco uses for exit when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. With this feature off, choco will exit with 0, 1, or -1 (matching previous behavior). Available in 0.9.10+. [ ] useEnhancedExitCodes - Use Enhanced Exit Codes - Chocolatey is able to provide enhanced exit codes surrounding list, search, info, outdated and other commands that don't deal directly with package operations. To see enhanced exit codes and their meanings, please run `choco [cmdname] -?`. With this feature off, choco will exit with 0, 1, or -1 (matching previous behavior). Available in 0.10.12+. [ ] exitOnRebootDetected - Exit On Reboot Detected - Stop running install, upgrade, or uninstall when a reboot request is detected. Requires 'usePackageExitCodes' feature to be turned on. Will exit with either 350 or 1604. When it exits with 350, it means pending reboot discovered prior to running operation. When it exits with 1604, it means some work completed prior to reboot request being detected. Available in 0.10.12+. [ ] useFipsCompliantChecksums - Use FIPS Compliant Checksums - Ensure checksumming done by choco uses FIPS compliant algorithms. Not recommended unless required by FIPS Mode. Enabling on an existing installation could have unintended consequences related to upgrades/uninstalls. Available in 0.9.10+. [x] showNonElevatedWarnings - Show Non-Elevated Warnings - Display non-elevated warnings. Available in 0.10.4+. [x] showDownloadProgress - Show Download Progress - Show download progress percentages in the CLI. Available in 0.10.4+. [ ] stopOnFirstPackageFailure - Stop On First Package Failure - Stop running install, upgrade or uninstall on first package failure instead of continuing with others. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.4+. [ ] useRememberedArgumentsForUpgrades - Use Remembered Arguments For Upgrades - When running upgrades, use arguments for upgrade that were used for installation ('remembered'). This is helpful when running upgrade for all packages. Available in 0.10.4+. This is considered in preview for 0.10.4 and will be flipped to on by default in a future release. [ ] ignoreUnfoundPackagesOnUpgradeOutdated - Ignore Unfound Packages On Upgrade Outdated - When checking outdated or upgrades, if a package is not found against sources specified, don't report the package at all. Available in 0.10.9+. [ ] skipPackageUpgradesWhenNotInstalled - Skip Packages Not Installed During Upgrade - if a package is not installed, do not install it during the upgrade process. Available in 0.10.12+. [ ] removePackageInformationOnUninstall - Remove Stored Package Information On Uninstall - When a package is uninstalled, should the stored package information also be removed? Available in 0.10.9+. [ ] logWithoutColor - Log without color - Do not show colorization in logging output. Available in 0.10.9+. [x] logValidationResultsOnWarnings - Log validation results on warnings - Should the validation results be logged if there are warnings? Available in 0.10.12+. [x] usePackageRepositoryOptimizations - Use Package Repository Optimizations - Turn on optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should generally be left enabled, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Available in 0.10.14+. [ ] scriptsCheckLastExitCode - Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0. [ ] disableCompatibilityChecks - Disable Compatibility Checks - Should a warning we shown, before and after command execution, when a runtime compatibility check determines that there is an incompatibility between Chocolatey and Chocolatey Licensed Extension. Available in 1.1.0+
Too bad the list is not sorted alphabetically nor you can ask for the status of a single feature as that would make searching for features a lot easier. Anyway: that’s why I marked it in bold above and posted two new issues:
- [Wayback/Archive] Please sort the output of `choco feature list` by default on feature name · Issue #2814 · chocolatey/choco
- [Wayback/Archive] Please amend `choco feature` with a verb to query a the status of a single feature name · Issue #2815 · chocolatey/choco
Note the remark in useRememberedArgumentsForUpgrades:
[ ] useRememberedArgumentsForUpgrades - Use Remembered Arguments For Upgrades - When running upgrades, use arguments for upgrade that were used for installation ('remembered'). This is helpful when running upgrade for all packages. Available in 0.10.4+. This is considered in preview for 0.10.4 and will be flipped to on by default in a future release.
At the time of writing (fall 2022) this feature does not yet seem to have been flipped on (I tested a more recent system with just the Chocolatey 1.1.0 installation).
I suspect it is because of at least the issue [Wayback/Archive] Upgrade all reuses overridden package parameters when useRememberedArgumentsForUpgrades feature is turned on · Issue #1443 · chocolatey/choco:
I have a multitude of packages installed via chocolatey, a number of which I have set custom install directories for. Chocolatey regularly shows error messages that indicate that the overridden parameters for another package are used.
…
As it turns out, this also happened to me:
[Wayback/Archive] http://disq.us/p/1qp8o56VLC got “upgraded” from 64 to 32bit on upgrade all after reusing remembered arguments that forced the 32bit upgrade for notepadplusplus earlier.
Arguments I wanted this for
The main reason for wanting arguments was the git installation:
choco upgrade --yes git.install --params "/GitAndUnixToolsOnPath /NoGitLfs /SChannel /NoAutoCrlf /WindowsTerminal"
Another one for some users is to force a package to be specifically installed as 32-bit instead of 64-bit, for instance Notepad++ above (so you have a broader set of plugins to choose from), which in full would be:
choco upgrade --yes --x86 notepadplusplus
Update workaround
The issue however has a workaround with an alternative cup-all function by [Wayback/Archive] TheCakeIsNaOH (TheCakeIsNaOH) that upgrades all Chocolatey packages individually in this [Wayback/Archive] comment · Issue #1443 · chocolatey/choco:
If anyone running into this issue a lot, here is one option:Function cup-all { if (!((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) { & gsudo.exe powershell.exe cup-all return } Write-Information "Checking for outdated packages" -InformationAction continue #choco outdated is slow. #$outdatedPackages = & choco.exe outdated -r --ignore-pinned $outdatedPackages = & roco.exe outdated -r if ($outdatedPackages) { $outdatedPackages | % { if (($_ -split "\|" | select -Last 1) -ne "true") { [array]$outdatedIds += $_ -split "\|" | select -First 1 } } Write-Information "Finished check; updating these packages:" -InformationAction continue $outdatedIds.ForEach({ Write-Information $_ -InformationAction continue }) $outdatedIds | % { & choco.exe upgrade $_ } } else { Write-Information "Finished check; no packages outdated" -InformationAction continue } }Stick it in your powershell profile. Auto elevates if needed, checks for outdated, then upgrade each outdated package individually, thus avoiding the reuse of arguments when multiple packages are upgraded with one command.It does requiregsudoandrocolateyinstalled. I’m using rocolatey sincechoco outdatedtakes over three minutes on my current main machine while roco is like 15 seconds.
Time to check out more details on PowerShell profiles
I have never had much in my PowerShell profile, so this finally looks like the time to put more in it. Hence [Wayback/Archive] about Profiles – PowerShell | Microsoft Docs
A PowerShell profile is a script that runs when PowerShell starts. You can use the profile as a logon script to customize the environment. You can add commands, aliases, functions, variables, snap-ins, modules, and PowerShell drives. You can also add other session-specific elements to your profile so they’re available in every session without having to import or re-create them.
…
PowerShell supports several profile files. Also, PowerShell host programs can support their own host-specific profiles.For example, the PowerShell console supports the following basic profile files. The profiles are listed in precedence order. The first profile has the highest precedence.
- All Users, All Hosts
- Windows –
$PSHOME\Profile.ps1- Linux –
/usr/local/microsoft/powershell/7/profile.ps1- macOS –
/usr/local/microsoft/powershell/7/profile.ps1- All Users, Current Host
- Windows –
$PSHOME\Microsoft.PowerShell_profile.ps1- Linux –
/usr/local/microsoft/powershell/7/Microsoft.Powershell_profile.ps1- macOS –
/usr/local/microsoft/powershell/7/Microsoft.Powershell_profile.ps1- Current User, All Hosts
- Windows –
$Home\Documents\PowerShell\Profile.ps1- Linux –
~/.config/powershell/profile.ps1- macOS –
~/.config/powershell/profile.ps1- Current user, Current Host
- Windows –
$Home\Documents\PowerShell\Microsoft.PowerShell_profile.ps1- Linux –
~/.config/powershell/Microsoft.Powershell_profile.ps1- macOS –
~/.config/powershell/Microsoft.Powershell_profile.ps1The profile paths include the following variables:
- The
$PSHOMEvariable stores the installation directory for PowerShell- The
$Homevariable stores the current user’s home directoryOther programs that host PowerShell can support their own profiles. For example, Visual Studio Code (VS Code) supports the following host-specific profiles.
- All users, Current Host –
$PSHOME\Microsoft.VSCode_profile.ps1- Current user, Current Host –
$Home\Documents\PowerShell\Microsoft.VSCode_profile.ps1In PowerShell Help, the “CurrentUser, Current Host” profile is the profile most often referred to as your PowerShell profile.…
To start PowerShell without profiles, use the NoProfile parameter of PowerShell.exe, the program that starts PowerShell.
…
PowerShell profiles aren’t run automatically in remote sessions, so the commands that the profiles add aren’t present in the remote session. In addition, the
$PROFILEautomatic variable isn’t populated in remote sessions.
There is more, but the above is a good summary of quotes from the documentation.
A nice tutorial on how to get started is [Wayback/Archive] How to Create a PowerShell Profile – Step-by-Step — LazyAdmin.
Related
- [Wayback/Archive] Chocolatey Software Docs | Feature
- [Wayback/Archive] Chocolatey Software | Chocolatey 0.10.14 0.10.14 (20190530)
- [Wayback/Archive] Chocolatey Software | Chocolatey 1.1.0 (20220330)
- [Wayback/Archive] “gsudo.exe” – Google Search
- [Wayback/Archive] “rocolatey” – Google Search
- [Wayback/Archive] about Profiles – PowerShell | Microsoft Docs
–jeroen






Leave a comment