经验分享 · 2025年11月8日

Avalonia application Debian / Ubuntu packaging

Avalonia Linux programs can be executed in most Linux distros by double-clicking the executable or by starting it from the terminal. Nevertheless, for a better user experience, it is recommended to have the program installed, so the user can start it via desktop shortcut, that exists in desktop environments such as GNOME and KDE, or via command-line, by having the program added to PATH.

Debian and Ubuntu related distros have their applications packaged in .deb files, that can be installed via sudo apt install ./your_package.deb.

Tutorial

In this tutorial, we will use the dpkg-deb tool to compile your .deb package.

1) Organize program files in a staging folder

Debian packages follow this basic structure:

Meaning of each folder:

  • DEBIAN: contains the control file.
  • /usr/bin/: contains the starter script (recommended for starting your program via command-line).
  • /usr/lib/myprogram/: where all files generated by dotnet publish go into.
  • /usr/share/applications/: folder for the desktop shortcut.
  • /usr/share/pixmaps/ and /usr/share/icons/hicolor/**: folders for application icons.
info

The /usr/share/icons/hicolor/** are optional, as in your app icon will probably show up on desktop even without those images, however, it is recommended to have them for better resolution.

2) Make the control file

The control file goes inside the DEBIAN folder.

This file describes general aspects of your program, such as its name, version, category, dependencies, maintainer, processor architecture and licenses. Debian docs have a more thorough description of all possible fields in the file.

Author’s comment

Don’t worry too much about filling all possible fields, most aren’t required. This tutorial is to make a “good-enough” Debian package.

The .NET dependencies can be listed by running apt show dotnet-runtime-deps-8.0 (suffix changes for other .NET versions); they will appear on the line starting with Depends: …. You can also check them in the .NET Core repo.

Avalonia required dependencies are: libx11-6, libice6, libsm6, libfontconfig1.

Overall, all .NET and Avalonia dependencies are required, plus any others specific of your app.

Below is a simple example of a control file.

3) Make the starter script

This step is recommended for two reasons: first, to reduce the complexity of the desktop shortcut, and second, to make your app runnable from Terminal.

The starter script file name should preferrably be myprogram (without .sh extension), so whenever your user types “myprogram” on the Terminal, he / she will start your program.

The myprogram_executable file usually has the same name as its .NET project, e.g., if your Avalonia .csproj project is named MyProgram.Desktop, then the main executable generated by dotnet publish will be MyProgram.Desktop.

Example of starter script:

4) Make the desktop shortcut

The desktop shortcut file follows the freedesktop specification. Arch Linux Wiki also has good related information.

Below is an example of a desktop shortcut file.

tip

If your app is supposed to open files, append %F at the end of the Exec line, after myprogram; if it’s supposed to open URLs, then append %U.

5) Add hicolor icons (optional)

Hicolor icons follow a folder structure like below.

This blog post advises us to put icons on both hicolor and pixmaps directories, according to Debian Menu System docs and FreeDesktop docs.

6) Compile the .deb package

Example of a Linux shell script for the entire process

To install

To uninstall / remove