by Ayan Gupta (LinkedIn, Twitter)
Creating a Chocolatey package from an EXE file allows you to distribute and automate your software installation on Windows systems. This guide will walk you through the process step-by-step.
We'll learn with an example of foss42/apidash .exe package which can be found here.
Prerequisites
- Chocolatey Installed: Ensure Chocolatey is installed on your system. refer Chocolatey Software | Installing Chocolatey
- EXE File: Have the installer executable (EXE file) of your application ready.
Step 1: Setup Skeleton
First step towards making a choco package is initializing a base.
The command choco new -h
can teach you more about the new
command, its usage, options, switches, and exit codes.
Run the following command to setup the base
choco new --name="apidash" --version="0.3.0" maintainername="foss42" maintainerrepo="https://github.com/foss42/apidash" --built-in-template
Explanation:
-
choco new
: Creates the structure and necessary files for a new Chocolatey package. -
--name="apidash"
: Specifies the name of the package, in this case, "apidash." -
--version="0.3.0"
: Sets the initial version of the package to0.3.0
. -
maintainername="foss42"
: Adds the name of the package maintainer, which is "foss42" in this example. -
maintainerrepo="https://github.com/foss42/apidash"
: Specifies the repository URL associated with the package, typically the source code or documentation link for "apidash." -
--built-in-template
: Uses Chocolatey's built-in package template to scaffold the package structure, including essential files likenuspec
and script files.
This creates the following folder structure
apidash
├── ReadMe.md
├── _TODO.txt
├── apidash.nuspec
└── tools
├── chocolateybeforemodify.ps1
├── chocolateyinstall.ps1
├── chocolateyuninstall.ps1
├── LICENSE.txt
└── VERIFICATION.txt
The files ReadMe.md
and _TODO.md
can be deleted before pushing.
The files of our main interest are chocolateyinstall.ps1
and apidash.nuspec
.
Step 2: Editing chocolateyinstall.ps1
Take a look at chocolateyinstall.ps1
file. There are many comments stating the use case of each line itself.
Update the following fields:
url
/url64
: To the URL of the .exe file hosted. In our case, it ishttps://github.com/foss42/apidash/releases/latest/download/apidash-windows-x86_64.exe
.filetype
: Could be eitherexe
,msi
, ormsu
. In our case, it is anexe
file.checksum
/checksum64
: set to the checksum of the .exe file for choco to match the hashes.silentArgs
: '/S' for .exe file.validExitCodes
:@(0)
Remove all the comments using the following command.
$f='apidash\tools\chocolateyinstall.ps1'
gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*? [^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f
Now our chocolateyinstall.ps1
file is ready.
Step 3: Editing apidash.nuspec
Change the following tags accordingly.
-
authors
: Name of author of software. -
projectUrl
: Url of the project. (maybe the one hosted on GitHub/Gitlab) -
iconUrl
: Url of the icon. (you could use githack.com if icon is in your repo itself) -
summary
: a summary of the package. -
description
: description of the package. -
tags
: tags specific to your package.
Step 4: Build the package
All our files are ready, we just need to pack out files in a choco package with the extension .nupkg
.
Run the following command from the root of your directory:
choco pack
This command generates the apidash.0.3.0.nupkg
file.
Step 5: Test the Package Locally
Install the package locally using Chocolatey:
choco install apidash -s .
Ensure the application installs correctly.
Step 6: Pre-Publishing - Update LICENSE.txt
& VERIFICATION.txt
Update LICENSE.txt
with the actual **LICENSE **and VERIFICATION.txt
accordingly.
Step 7: Publish the Package (Optional)
To share the package, you can push it to a Chocolatey repository. For the official Chocolatey Community Repository, follow these steps:
- Create an account on the Chocolatey Community.
- Get an API key by navigating to your profile.
- Use the following command to push your package:
choco push MyPackage.1.0.0.nupkg --source="https://push.chocolatey.org/" --api-key="YOUR_API_KEY"
Conclusion
Creating a Chocolatey package from an EXE file simplifies software deployment on Windows systems. By following the steps outlined in this guide, you can easily build, test, and publish your custom Chocolatey package.
Top comments (0)