Module 4 · Lesson 16 of 16
From dotnet run to someone else's desktop
Publishing is a checklist. Pick a runtime story, keep trimming honest, add the desktop entry, and test the artifact on a machine that never saw the SDK.
dotnet run is not a distribution strategy. It assumes an SDK, a terminal, and the
current directory. Shipping means a file someone can double-click, on a machine you
have never seen.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<RootNamespace>CourseApp</RootNamespace>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<None Remove="app.manifest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="12.2.0" />
<PackageReference Include="Avalonia.Desktop" Version="12.2.0" />
<PackageReference Include="Avalonia.Themes.Fluent2" Version="12.2.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.2.0" />
<PackageReference Include="Avalonia.Wayland" Version="12.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
</ItemGroup>
</Project>
Pick a runtime story
| Approach | Command | Trade-off |
|---|---|---|
| Framework-dependent | dotnet publish -c Release -r linux-x64 |
~10 MB; requires the .NET runtime |
| Self-contained | add --self-contained |
~70 MB; no install step |
| Single file | add -p:PublishSingleFile=true |
one managed binary, but native libraries stay beside it |
| Single file + natives | add -p:IncludeNativeLibrariesForSelfExtract=true |
one file; extracts natives to temp on first start |
| Trimmed | add -p:PublishTrimmed=true |
smaller; reflection is dangerous |
| Native AOT | -p:PublishAot=true |
fast start, tiny; strictest constraints |
For a desktop app that people install once, self-contained single-file is the boring, reliable default.
PublishSingleFile is not enough on its own. Avalonia depends on native
libSkiaSharp and libHarfBuzzSharp. Without
IncludeNativeLibrariesForSelfExtract=true, the publish output is a 12 MB
executable plus those two .so files — ship the folder or add the property. This
was verified by publishing this app both ways and launching the result.
Trimming and AOT are not free with XAML
Avalonia's compiled bindings are what make trimming viable. Reflection-based bindings, some converters, and dynamically loaded assemblies are trimmed away unless you tell the linker otherwise. This sample sets:
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
That single property is why the lessons write x:DataType everywhere. Test the
trimmed build by running the published binary, not by reading the size.
The desktop entry
[Desktop Entry]
Type=Application
Name=Avalonia Field Guide
Comment=Thirteen Avalonia samples in one window
Exec=/opt/field-guide/CourseApp
Icon=avalonia-field-guide
Terminal=false
Categories=Development;Education;
StartupWMClass=CourseApp
Install it to ~/.local/share/applications/ (per user) or
/usr/share/applications/ (system). Exec must be an absolute path or a command on
PATH. StartupWMClass matters on X11: without it the launcher shows a generic
icon and cannot group windows.
Icons go in ~/.local/share/icons/hicolor/<size>/apps/, at 128 and 256 px.
Icon= is a name, not a path.
Then package it
- Flatpak — the sandboxed, cross-distro answer. Needs a manifest and a runtime; portals replace raw filesystem access.
- AppImage — one executable, no install. Fast to produce, weak on updates.
.deb/.rpm— integrate with the distro, but you own the dependency list.- A tarball — honest and underrated for internal tools.
Whichever you choose, the last step is the same: install it on a clean VM, launch
it from the desktop menu, and use it for ten minutes. Not ./app --version.
Versioning and crashes
- Put the version in one place (
<Version>in the csproj) and show it in an About page. - Catch unhandled exceptions at the
AppDomainlevel and offer a copyable crash report; a silent exit is the worst failure mode. - Log to
$XDG_STATE_HOME/<app>/unless you have a better reason.
Try it
- Publish self-contained and single-file (with the native-libraries property),
then run the binary from
/tmpwith the SDK directory renamed. It must still start. Then remove the property, publish again, and see the.sofiles appear. - Add the icon and
.desktopfile, log out and back in, and launch from the menu. - Build a Flatpak. Watch which permissions the sandbox denies first; that list is the real design review.
That is the end of the course. Build something small and finish it.
Files this lesson draws from
src/CourseApp/CourseApp.csprojdeploy/avalonia-field-guide.desktop
VerifiedThe verifier checks that the shipping checklist has no empty steps and that its completed count matches the steps marked done.