General Information and Nuspec
There are four main elements to a Chocolatey package. Only the nuspec is required (#1 below).
- chocolateyInstall.ps1 - check out the helper reference
- Any application files to include (it is highly suggested that you are the author in this case or you have the right to distribute files). EXE files in the package/downloaded to package folder from chocolateyInstall.ps1 will get a link to the command line.
- chocolateyUninstall.ps1, for uninstalling your package. See helper reference for functions available in your script.
Please maintain compatibility with Posh v2. Not every OS we support is on Posh v2 (nor comes OOB with Posh v3+). It's best to work with the widest compatibility of systems out there.
There is a video showing the creation of a package: http://www.youtube.com/watch?v=Wt_unjS_SUo
The video is a bit outdated in showing the contents of the chocolateyInstall.ps1. Have a look at what the chocolateyInstall.ps1 looks like now:
$packageName = 'windirstat' $fileType = 'exe' $url = 'http://prdownloads.sourceforge.net/windirstat/windirstat1_1_2_setup.exe' $silentArgs = '/S' Install-ChocolateyPackage $packageName $fileType $silentArgs $url
Scenarious When Custom Scripts Are Triggered
The table below shows which scripts are available, and which command(s) will cause them to be run.
In the upgrade scenario, the chocolateyInstall.ps1 script will be the one included in the new package. The chocolateyBeforeModify.ps1 script will be the one from the previously installed package.
The chocolateyBeforeModify.ps1 script will only be executed if using choco version 0.9.10 or later.
Chocolatey Windows package manager uses the same infrastructure as NuGet, the Visual Studio package manager by Outercurve Foundation (sponsored by Microsoft). Therefore packages are based on the same principles. One of those is a package description (specification) in
xml format, known as the
Nuspec contains basic information such as the version, license, maintainer, and package dependencies.
Chocolatey includes additional optional functionality on top of NuGet's Nuspec format - the best way to determine currently supported features is to create a test package, and look at the generated nuspec file.
choco new testpackage
If your package uses recently introduced functionality, you might want to include
chocolatey as a dependency with the version being the lowest version that has the introduced functionality. Otherwise the installation could fail for users with an older version of
You can indicate the
Chocolatey dependency like any other dependency. E.g.:
<dependencies> <dependency id="chocolatey" version="0.9.8.21" /> </dependencies>
Logically, the version is based on the lowest compatible version. But if you don't know and used a lot of sorcery in your package, depend on the version of
Chocolatey that you succesfully tested your package on.
See also: NuGet Version Reference