Search⌘ K
AI Features

Publishing a Single-File App

Explore how to publish single-file .NET applications efficiently across different platforms. Learn to manage dependencies when .NET is or isn't installed, and understand app trimming techniques introduced in .NET Core 3.0 and enhanced in .NET 5 and 6 to minimize deployment size. This lesson helps you build and deploy compact, self-contained apps with control over included components.

To publish as a “single” file, we can specify flags when publishing. With .NET 5, single-file apps were primarily focused on Linux because there were limitations in Windows and macOS that meant true single-file publishing was not technically possible. With .NET 6 or later, we can create proper single-file apps on Windows.

Publishing on systems with .NET already installed

Suppose we can assume that .NET is already installed on the computer on which we want to run our app. In that case, we can use the extra flags when we publish our app for release to say that it does not need to be self-contained and that we want to publish it as a single file (if possible), as shown in the following command (which must be entered on a single line):

dotnet publish -r win10-x64 -c Release --no-self-contained /p:PublishSingleFile=true
Command to publish as a single-file

This will generate two files: DotNetEverywhere.exe and DotNetEverywhere.pdb. The ...