dotnet publish: self-contained vs framework-dependent, single-file, ReadyToRun and Native AOT
dotnet publish can produce very different outputs from the same project: a small framework-dependent app that needs .NET installed, a self-contained folder that carries its own runtime, a single file, a ReadyToRun build or a Native AOT executable. This guide explains each mode with the exact command, what it produces, and how to choose.
The two deployment modes From the source
Every .NET app is published in one of two modes. Microsoft's publishing overview defines them like this, and everything else (single-file, ReadyToRun, Native AOT) is an option layered on top.
- Framework-dependent: the publish folder contains your compiled app and its dependencies, plus an optional platform-specific executable to start it. The machine that runs the app must already have a compatible .NET runtime installed. This is the default when you publish from the CLI or Visual Studio.
- Self-contained: the publish folder also contains the .NET runtime itself, so the target machine needs no .NET install. It does not include .NET's native operating system dependencies, which must already be present on the machine.
At a glance · .NET
The two deployment modesThe commandsTrade-offs Microsoft listsThe apphost and the DLLWhich should you choose?Common mistakes
The commands From the source
All of these use the Release configuration, which is what dotnet publish uses by default unless you change it with -c. -r takes a runtime identifier (RID) such as win-x64 or linux-x64, which picks the target operating system and CPU and makes sure native dependencies are included.
- Framework-dependent: dotnet publish -c Release, optionally with -r <RID> to produce an executable for one platform. Add --self-contained false to make the mode explicit.
- Framework-dependent, DLL only: dotnet publish -c Release -p:UseAppHost=false produces only the portable myapp.dll, which you start with dotnet myapp.dll.
- Self-contained: dotnet publish -c Release -r <RID> --self-contained true.
- Single file: add -p:PublishSingleFile=true to either mode.
- ReadyToRun: add -p:PublishReadyToRun=true to either mode.
- Native AOT: set PublishAot to true in a PropertyGroup in the project file (Visual Studio's publish UI cannot enable it), then publish with -r <RID>.
- Container image: dotnet publish -c Release -t:PublishContainer. Since .NET SDK 8.0.200 container support is built in and needs no extra NuGet package.
- Multi-targeted project: add -f with the target framework, for example -f net10.0. Output goes to bin/Release/<TFM>/publish.
Trade-offs Microsoft lists From the source
- Framework-dependent: small deployment, runs on any operating system that has the runtime, and uses the latest patched runtime on the machine. But the runtime must be installed first, and the runtime it runs on can change when the machine is updated.
- Self-contained: you control the exact .NET version and target one platform. But deployments are larger, and updating .NET means republishing and redeploying the app.
- Single-file: simple distribution and fewer files, but a larger file, slower startup because files are extracted at run time, and always one operating system and architecture.
- ReadyToRun: faster startup and first use because assemblies are precompiled, works with existing code and with both modes, but files are larger and builds take longer.
- Native AOT: fast startup, lower memory use, no runtime dependency and a smaller deployment, but limited framework support, longer builds, one platform per build and harder debugging. It always uses self-contained mode.
The apphost and the DLL From the source
Even a framework-dependent, cross-platform publish creates a small platform-specific launcher called the apphost (myapp.exe on Windows, myapp elsewhere) next to myapp.dll, because the UseAppHost property defaults to true. Microsoft recommends starting apps through the apphost whenever possible rather than with dotnet myapp.dll.
When the apphost runs a framework-dependent app, it has to find a .NET install. Microsoft's advice for a non-default install location is to clear every environment variable that starts with DOTNET_ROOT, set only DOTNET_ROOT to the install path, then run the apphost. From .NET 9, the AppHostDotNetSearch and AppHostRelativeDotNet properties let you build that search into the apphost instead.
Which should you choose? Analysis
Microsoft does not give one rule; the deciding factors are whether the target machine has a suitable .NET runtime and whether you need a feature that requires bundling the runtime. In practice:
- Web apps and APIs in containers or on Azure App Service: framework-dependent on an official .NET base image or a platform with .NET installed. Images are smaller, and security patches arrive by updating the base image or platform instead of republishing.
- Tools you hand to other people, on machines you do not control: self-contained, usually with PublishSingleFile, so users get one file and do not need to install .NET.
- Command-line tools, serverless functions and small services where startup time and memory matter: try Native AOT, but test every library you use, because reflection-heavy code may not be supported.
- Large apps with slow startup that cannot move to Native AOT: ReadyToRun is the low-risk middle ground.
- Whatever you pick, remember who installs security fixes. With framework-dependent apps it is whoever patches the machine or image; with self-contained, single-file and Native AOT apps it is you, by republishing on every .NET servicing update.
Common mistakes Analysis
- Publishing self-contained without -r: a self-contained or single-file app is always for one platform, so pass the RID you deploy to (linux-x64 for most Linux servers and containers, linux-arm64 for Arm machines, win-x64 for 64-bit Windows).
- Using --no-build with different options: if you publish with --no-build, use exactly the same target framework and configuration you built with.
- Forgetting native dependencies on Linux: self-contained apps still need the operating system libraries .NET depends on, so slim base images or minimal servers can fail at startup even though the runtime is bundled.
- Shipping large self-contained apps: trimming or globalization invariant mode can reduce the size of self-contained apps; Microsoft documents both under publishing options.
Sources and further reading
- .NET application publishing overview (Microsoft Learn) (original source)
- .NET RID catalog (Microsoft Learn) (documentation)
- Download .NET (official)
Original: “.NET application publishing overview”, Microsoft Learn, published 25 Nov 2026, retrieved 25 Nov 2026. This article was generated from the official source using our structured templates and passed automated quality checks. Spotted a mistake? See our corrections policy.