Every way to ship an app
dotnet publish framework-dependent or self-contained, single file, trimmed, Native AOT, as a container, or as a NuGet package. What each one puts on the other machine.
Start from the machine you're shipping to, and add options only when you need what they give.
- The machine has (or can get) the .NET runtime → a plain
dotnet publish: framework-dependent, Release, small, and it picks up runtime security patches when the machine updates .NET. - The machine has no .NET, or you can't control which one →
self-contained with a runtime identifier,
dotnet publish -r linux-x64 --self-contained. Bigger, one OS and CPU, and you patch the runtime by republishing. - Users want one file to copy → add
PublishSingleFile. It works with either mode above. - Startup time and size matter (a CLI tool, a serverless function) → Native AOT, if every library you use is trim- and AOT-safe. Treat each IL2xxx or IL3xxx warning as a bug.
- It runs on a server or in the cloud → a container image,
dotnet publish -t:PublishContainer, no Dockerfile needed. - Other developers will use it as a library →
dotnet packand publish a NuGet package.
Whatever you ship, ship the publish folder, never bin/Debug, and
let CI build it the same way every time.
Build, run or publish
Section
Build, run and publish
The build folder is for your machine; the publish folder is for everyone else's.
Choosing what to include
Bring the runtime or rely on the machine's, and who patches it afterwards.
linux-x64, win-arm64 and friends, and bundling the app into one executable.
Section
Trimming and Native AOT
Smaller and faster to start, at the price of reflection. The warnings tell you what would break.
Where it runs
Section
Containers
An image built by the SDK on a Microsoft base image, run the same way everywhere.
dotnet pack, package metadata and versioning, when your "app" is a library.
Every time, automatically
Section
Continuous integration
A workflow that builds, tests and publishes on every push, so shipping isn't a manual ritual.
Section
The capstone, shipped
The whole route end to end, from publish to a running container and a green CI run.