Now that Hook scripts are a built in to open source Chocolatey CLI, there is no need for the choco-hooks.extension
.
I'd suggest uninstalling choco-hooks.extension
, and using the built in hook support instead. I'm moving my hook development to https://github.com/chocolatey-community/chocolatey-hooks, and discontinuing this repository.
The Hook scripts that are built into Chocolatey are similar to the hook scripts I added support for here, but with a few key differences. First, the folder name is hooks
not choco-hooks
, and second the filename format is seperated by a dash "-", not an underscore "_", and finally, use beforemodify
instead of modify
and all
instead of any
. These should be just a few renames away from working. The Hook scripts build into Chocolatey also are able to run even if the package does not have a package automation script.
This project is not associated with Chocolatey Software, Inc.
Installing the choco-hooks.extension
package will modify a file in your install of choco.
Therefore, please DO NOT contact Chocolatey support with any issues if this is installed.
Report them to the issue tracker here instead.
This is a modification to choco that allows you to run PowerShell scripts before and after the scripts in Chocolatey package run.
The hook scripts can be run for all packages, or for a specific package id. They can be run for only install/uninstall/modify, or they can be run for all.
It is an implementation of this choco feature request.
- Make sure you are running choco
0.10.15
,0.10.16-beta-20200806
,0.11.0
, or0.11.1
. - Run
choco pin add -n chocolatey
, which prevents choco from upgrading until you are ready.
- Clone or otherwise acquire this repository
- Run
choco pack
in thechoco-hooks.extension
directory - Run
choco install choco-hooks.extension -s .
in thechoco-hooks.extension
directory
- Add the myget repository:
choco source add -n choco-hooks -s https://www.myget.org/F/choco-hooks/api/v2
- Install:
choco install choco-hooks.extension
choco uninstall choco-hooks.extension -f
choco pin remove -n chocolatey
choco upgrade chocolatey
choco pin add -n chocolatey
choco install choco-hooks.extension
- Uninstall any
.chook
packages you have installed. choco uninstall choco-hooks.extension
choco pin remove -n chocolatey
- Remove
$env:ChocolateyInstall\choco-hooks\
Hook scripts can be skipped by adding the /SKIPHOOKS
package parameter, like --params="'/SKIPHOOKS'"
Name in the format: time_type_id.ps1
.
- Time is either
pre
orpost
, to run before or after the package script. - Type is
install
,uninstall
,modify
orany
, which will run forchocolateyInstall.ps1
,chocolateyUninstall.ps1
,chocolateyBeforeModify.ps1
and any of those, respectively. - ID is the id of the package you want it to run for. Alternatively
all
can be used used to run for all packages.
So pre_install_all.ps1
would run before chocolateyInstall.ps1
for all packages. Or post_uninstall_firefox.ps1
would run after chocolateyUninstall.ps1
Feel free to add other .ps1
files with other names that contain common functions or similar. Script that do not match the naming will be ignored.
The script sho 6DAB uld have access to all the functions and environment variables a package script has. See here for a reference for the ones built in to choco.
Create a folder under $env:ChocolateyInstall\choco-hooks\
and place your .ps1
scripts in it.
I would suggest naming starting with an underscore (_
), to make sure that it does not get overwritten by a .chook
package.
- Create a package with an ID ending in
.chook
or.chook.extension
. - Add a folder in the top level of the package called
hook
- Put your hook scripts in the hook dir
- Pack and install the package.
NOTE: Make sure you keep the chocolateyInstall.ps1
and chocolateyUninstall.ps1
scripts in the package, otherwise the hooks will not be copied/removed. They can be empty, but they need to exist in the package.
The main limitation of this is that hook scripts will not be triggered if a package does not have scripts.
In the choco feature request, is is undecided by Chocolatey if hooks are a feature that would go in open source Choco, or in the licensed extension. Or if possibly hooks would be a feature that would have gimped functionality in open source, but more features in licenced.
From what I can tell from public statements, it is the current policy that pull requests which implement features from the licensed version of Chocolatey are automatically closed, and will not be accepted. Therefore, until there is decision on where hooks would end up in choco, it is pointless to work on implementing this in upstream choco.
Secondarily, since choco 0.10.15 released in early 2019, there has been not very much work done on FOSS choco, as Chocolatey committers are working on things for licensed editions instead. From what I can tell from public statements, the next major activity on open source choco is planned to start at the end of 2021. I want hooks before that.
First, this is modifying the choco script runner, which I know for a fact would not be allowed through moderation unless it was given the blessing of a Chocolatey admin.
Second, since hooks might be a licensed feature, this might not be allowed on the community repository, since packages that implement licensed features are generally not allowed ref