DEV Community

Cover image for Packaging and Distributing Flutter Desktop Apps: The Missing Guide for Open Source & Indie Developers - Packaging choco packages
Ayan
Ayan

Posted on

1

Packaging and Distributing Flutter Desktop Apps: The Missing Guide for Open Source & Indie Developers - Packaging choco packages

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
Enter fullscreen mode Exit fullscreen mode

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 to 0.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 like nuspec and script files.

choco folder structure

This creates the following folder structure

apidash
├── ReadMe.md
├── _TODO.txt
├── apidash.nuspec
└── tools
    ├── chocolateybeforemodify.ps1
    ├── chocolateyinstall.ps1
    ├── chocolateyuninstall.ps1
    ├── LICENSE.txt
    └── VERIFICATION.txt
Enter fullscreen mode Exit fullscreen mode

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 is https://github.com/foss42/apidash/releases/latest/download/apidash-windows-x86_64.exe.

  • filetype: Could be either exe, msi, or msu. In our case, it is an exe 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
Enter fullscreen mode Exit fullscreen mode

chocolatelyinstall.ps1

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.

final apidash.nuspec

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 
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

Ensure the application installs correctly.

Shell output


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:

  1. Create an account on the Chocolatey Community.
  2. Get an API key by navigating to your profile.
  3. 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"
Enter fullscreen mode Exit fullscreen mode

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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series