Publish a simple executable from Rust on Chocolatey 🍫
Tags: rust, devops, backend
Published: 2020-09-04 06:51:00

The most comfortable way to install software on Windows is thorugh [Chocolatey](https://chocolatey.org) 🍫 And in this guide you will learn how to do that! 🤩 At least for simple executables 🐣

I successfully published my Rust app [vidmerger](https://chocolatey.org/packages/vidmerger) in that way! 🎞✨

# 🐣 Initializing 

First of all install the [cli-tool](https://chocolatey.org/install) for Chocolatey:

```powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
```

Then run `choco new my-app` to generate a folder called `my-app` with the following content:

```bash
my-app
├── ReadMe.md
├── _TODO.txt
├── my-app.nuspec
└── tools
    ├── LICENSE.txt
    ├── VERIFICATION.txt
    ├── chocolateybeforemodify.ps1
    ├── chocolateyinstall.ps1
    └── chocolateyuninstall.ps1
```

The minimal setup for publishing would look like:

```bash
my-app
├── my-app.nuspec
└── tools
    ├── LICENSE.txt
    └── VERIFICATION.txt
```

The `*.ps1` files are basically for defining shell commands which run on `beforemodify`, `install` and `uninstall`. We don't really need them for publishing a simple executable.

Put your `*.exe` file from Rust or whatever into the `tools` folder 🦀

# ⚙️ Modifying

I think I'll just show you here my three modified files from my Rust app [vidmerger](https://chocolatey.org/packages/vidmerger), modify them accordingly 👇

## 🎴 my-app.nuspec

```xml
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>vidmerger</id>
    <version>0.1.2</version>
    <title>vidmerger</title>
    <authors>Thomas Gotwig</authors>
    <projectUrl>https://github.com/tgotwig/vidmerger</projectUrl>
    <tags>video cli</tags>
    <summary>A wrapper around ffmpeg which simplifies merging multiple videos 🎞</summary>
    <description>Vidmerger is a command-line-tool which uses `ffmpeg` to merge multiple video-files with the same file-extension together into one file called `output.FORMAT`. It includes a usage help which you can print out by `vidmerger --help` 😃</description>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>
```

## 🎴 LICENSE.txt

```
Copyright 2020 Thomas Gotwig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

## 🎴 VERIFICATION.txt

```
Generated by `CertUtil -hashfile vidmerger.exe SHA256`:

1268967539be0449126438887170c779aaea6fdbf4d835e529c77d4c56a7f75d
```

Think on updating the hash inside of `VERIFICATION.txt` before pushing 🧐

# 🚀 Pushing

Before you can push something, you'll need to login on your choco-cli first, to do so, go on `https://chocolatey.org/account`, do a login there and click on `Show API Key`, run that listed commands in your console.

Finally lets push it to Chocolatey! 😃

```powershell
choco pack
Get-ChildItem *.nupkg | ren -NewName vidmerger.nupkg
choco push vidmerger.nupkg --source https://push.chocolatey.org
Remove-Item vidmerger.nupkg
```

That's all! 😊🍫