Building, Testing, and Pushing Your Package
Building Your Package
Open a command line in the directory where the nuspec is and type
choco pack. That's it.
Testing Your Package
To test the package you just built, open a command line shell and navigate to the directory where the
*.nupkg file is located. Then type:
choco install packageName -dv -s .
This will install the package right out of your source. As you find things you may need to fix, using
-f) will remove and reinstall the package from the updated
*.nupkg. If you are specifically testing
chocolateyBeforeModify.ps1, you need to be testing upgrade and uninstall scenarios. You need to install a version of the package with this file first as before modify is like uninstall, it runs from the installed package, not the package you are installing (like
-f) should only be done in subsequent testing where you are reinstalling the same package that you've changed and should NOT be used in regular use scenarios. It should definitely not be in scripts.
-preswitch or else you will get Unable to find package errors from
choco install. You can also specify
-version 1.0.0-betato try to install that exact version.
. points to the current directory. You can specify multiple directories separated by a semicolon;
nuspec specifies dependencies that are not in your source, you should add their paths to the source directory. E.g. in the case of Chocolatey itself:
<dependencies> <dependency id="chocolatey" version="0.9.8.20" /> </dependencies>
You'll need to append the API path like so:
-source "'.;https://chocolatey.org/api/v2/'" (note the double quotes bookending the apostrophes here, use
%cd% in cmd.exe or
$pwd in Powershell.exe if
. doesn't resolve). See passing options with quotes. Note: If you need to do this, please ensure you run
choco pack first. This method of passing a source won't work calling a nuspec or nupkg directly as it will override the source passed to the local folder.
You can also use the
-debug switch on
choco install to provide more information.
.nupkg- pointing to a file explicitly overrides source. You must call your install with the package name, not the nupkg file and location. You've already specified for choco to look in a local source with
-s "'.;https://chocolatey.org/api/v2/'". Call
choco install dude -s "'.;https://chocolatey.org/api/v2/'", not
choco install .\dude.nupkg -s "'.;https://chocolatey.org/api/v2/'".
Alternative testing strategy
You can also type
choco install -fdv path/to/nuspec and choco will build the nupkg and attempt to install it.
Pushing Your Package
To push your package after you have built and tested it, you type
choco push packageName.nupkg -s sourceLocation where packageName.nupkg is the name of the nupkg that was built with a version number as part of the package name and sourceLocation is the location of the source you want to push to (e.g.
https://push.chocolatey.org/ for chocolatey's community feed). You must have an api key for https://chocolatey.org/ set. Take a look at choco push