The first way needs dotnet runtime to run, the second way I will share the self contained without dotnet runtime.
Need: dotnet runtime
Step 1: Install System-Wide .NET SDK (Required)
Open a terminal and run:
# Add Microsoft's repository
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
# Install .NET 8 SDK
sudo apt update
sudo apt install -y dotnet-sdk-8.0
# Verify installation
dotnet --version
Step 2: Install dotnet-deb Tool
dotnet tool install --global dotnet-deb
Step 3: Prepare Your Avalonia Project
- Open your
.csproj
file - Add these lines inside the
<PropertyGroup>
section:
<DebianPackage>true</DebianPackage>
<DebianPackageDependencies>libc6, libgcc1, libstdc++6</DebianPackageDependencies>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
Step 4: Build the .deb Package
dotnet deb -c Release -r linux-x64
This will create a .deb
file in:
/bin/Release/net8.0/linux-x64/[your-app-name].deb
Step 5: Install on Ubuntu
sudo apt install ./bin/Release/net8.0/linux-x64/[your-app-name].deb
Step 6: Run Your App
- Find it in your application menu, or run via terminal:
[your-app-name]
Troubleshooting Tips
1- Missing dependencies? Run:
sudo apt install libx11-dev libgbm-dev libgl1-mesa-dev
2- Not showing in app menu?
Check the generated .desktop
file in:
/usr/share/applications/[your-app-name].desktop
3- Want a custom icon?
Add this to your .csproj
:
<DebianPackageIcon>path/to/your/icon.png</DebianPackageIcon>
4- You must install .NET to run this application.
export DOTNET_ROOT=/usr/share/dotnet/
Clean Uninstall Later
sudo apt remove [your-app-name]
note: Self contained:
To create a self-contained .deb package that doesn't require users to install .NET separately, follow these steps:
1. Modify Your .csproj
File
Add these properties to ensure a self-contained deployment:
<PropertyGroup>
<!-- Enable self-contained deployment -->
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<!-- Required for dotnet-deb -->
<DebianPackage>true</DebianPackage>
<DebianPackageDependencies>libc6, libgcc1, libstdc++6</DebianPackageDependencies>
</PropertyGroup>
2. Publish & Build the .deb Package
Run this command to generate a standalone .deb:
dotnet publish -c Release -r linux-x64 --self-contained true
dotnet deb -c Release -r linux-x64
This will output a .deb
file in:
bin/Release/net8.0/linux-x64/[your-app-name].deb
3. Key Improvements
- No .NET Runtime Needed: The app bundles everything required.
-
Single Executable:
PublishSingleFile
reduces file clutter. -
Debian Dependencies: Only basic system libs (
libc6
, etc.) are required.
4. Install & Test on Another Machine
sudo apt install ./your-app-name.deb
your-app-name
The app should run without requiring dotnet
installation.
Troubleshooting
If you get library errors, ensure these are installed:
sudo apt install libx11-dev libgbm-dev libgl1-mesa-dev
Final notes
-
SelfContained=true
bundles the .NET runtime inside your app. -
PublishSingleFile
merges DLLs into one executable. - The
.deb
package handles installation like any native app.
Thank you.
We’re thrilled to announce a limited-time token giveaway now live for Dev.to contributors to celebrate our authors' impact in Web3! Click here here (wallet connection required). – Dev.to Community Support