Chocolatey: forcing a certain package version and pinning it at that version
Posted by jpluimers on 2021/09/23
For my future self.
Due to an issue with choco-cleaner versions [WayBack] 0.0.6 and [WayBack] 0.0.7, I needed to ensure it was installed as version [WayBack] 0.0.5.2 and keep it that version.
Not sure if this is the canonical way, but this worked:
choco uninstall --yes choco-cleaner choco install --yes choco-cleaner --version 0.0.5.2 choco pin add --name=choco-cleaner --version 0.0.5.2 choco pin list
This worked to revert:
choco pin remove --name=choco-cleaner choco pin list choco upgrade --yes choco-cleaner
Aftere this upgrade, choco-cleaner version 0.0.7.1 shows a nice error message when the environment variable %ChocolateyToolsLocation% fails to exist.
In that case calling RefreshEnv.cmd will create that environment variable.
Related:
- [WayBack] Chocolatey Software | Commandsinstall: Examples
- [WayBack] Chocolatey Software | Commandspin: examples
- [WayBack] Chocolatey Software | (unofficial) Choco Cleaner (Script + Task) 0.0.7: releasenotes
- [WayBack] Lack of `ChocolateyToolsLocation` environment variable causes `choco-cleaner` to fail in an UAC console · Issue #143 · bcurran3/ChocolateyPackages · GitHub
Default
%ChocolateyToolsLocation%location is%systemdrive%\toolsaccording to [WayBack] https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-ToolsLocation.ps1#L61 - [WayBack] Installed to c:\tools\bcurran3 · Issue #112 · bcurran3/ChocolateyPackages · GitHub
The readme.md on GitHub is out of sync… a bunch of stuff is that I need to get to eventually.
The new package page on chocolatey.org should be current and has this:
Release Notes
INSTRUCTIONS:
Edit C:\tools\BCURRAN3\choco-package-list-backup.config to customize your backup(s). It’s easy, there are comments.
From PowerShell or the Command Prompt, type CHOCO-PACKAGE-LIST-BACKUP to backup your Chocolatey packages list.
From Windows, click Chocolatey Package List Backup in the Windows Start Menu or Package List Backup inside the Chocolatey folder if Chocolatey Shortcuts is installed.
CHANGELOG:
2019.08.27 – can now put title and summary info into the packages.config file, new -EditConfig parameter to edit the config file, Now works from Command Prompt as well as PowerShell, script installation endpoint changed, config file renamed from .xml to .config
–jeroen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| C:\bin\bin>choco upgrade choco-cleaner | |
| Chocolatey v0.10.15 | |
| Upgrading the following packages: | |
| choco-cleaner | |
| By upgrading you accept licenses for the packages. | |
| You have choco-cleaner v0.0.5.2 installed. Version 0.0.7.1 is available based on your source(s). | |
| Progress: Downloading choco-cleaner 0.0.7.1… 100% | |
| choco-cleaner v0.0.7.1 [Approved] | |
| choco-cleaner package files upgrade completed. Performing other installation steps. | |
| The package choco-cleaner wants to run 'chocolateyinstall.ps1'. | |
| Note: If you don't run this script, the installation will fail. | |
| Note: To confirm automatically next time, use '-y' or consider: | |
| choco feature enable -n allowGlobalConfirmation | |
| Do you want to run the script?([Y]es/[A]ll – yes to all/[N]o/[P]rint): y | |
| SUCCESS: The scheduled task "choco-cleaner" was successfully deleted. | |
| PATH environment variable does not have C:\tools\BCURRAN3 in it. Adding… | |
| Refreshing environment variables from the registry for powershell.exe. Please wait… | |
| Finished | |
| Adding C:\ProgramData\chocolatey\bin\choco-cleaner.bat and pointing it to powershell command C:\tools\BCURRAN3\choco-cleaner.ps1 | |
| SUCCESS: The scheduled task "choco-cleaner" has successfully been created. | |
| Folder: \ | |
| TaskName Next Run Time Status | |
| ======================================== ====================== =============== | |
| choco-cleaner 1/19/2020 11:00:00 PM Ready | |
| Now configured to run choco-cleaner at 11:00 PM every SUNDAY. | |
| You can manually run choco-cleaner from the Command Prompt and Powershell. | |
| Environment Vars (like PATH) have changed. Close/reopen your shell to | |
| see the changes (or in powershell/cmd.exe just type `refreshenv`). | |
| The upgrade of choco-cleaner was successful. | |
| Software install location not explicitly set, could be in package or | |
| default install location if installer. | |
| Chocolatey upgraded 1/1 packages. | |
| See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). | |
| C:\bin\bin>set | grep -i choco | |
| ChocolateyInstall=C:\ProgramData\chocolatey | |
| ChocolateyLastPathUpdate=132046303523761893 | |
| Path=C:\Program Files\ImageMagick-7.0.9-Q16;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd; | |
| C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\bin\bin;C:\Program Files\Mercurial\;;C:\Users\jeroenp\AppData\Local\Programs\Fiddler | |
| Path_HKLM=C:\Program Files\ImageMagick-7.0.9-Q16;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git | |
| \cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin | |
| C:\bin\bin>%ChocolateyInstall%\bin\choco-cleaner.bat | |
| Choco-Cleaner.ps1 v0.0.7.1 (01/16/2020) – deletes unnecessary residual Chocolatey files to free up disk space | |
| Copyleft 2017-2020 Bill Curran (bcurran3@yahoo.com) – free for personal and commercial use | |
| WARNING: $env:ChocolateyToolsLocation not defined. | |
| ScriptHalted | |
| At C:\tools\BCURRAN3\choco-cleaner.ps1:11 char:98 | |
| + … not defined.' ;throw} | |
| + ~~~~~ | |
| + CategoryInfo : OperationStopped: (:) [], RuntimeException | |
| + FullyQualifiedErrorId : ScriptHalted |






Leave a comment