dotnet publish: Produce a Deployable Build
dotnet publish compiles an app and copies it plus its dependencies into a folder ready to deploy or containerize.
publish is the build you ship. It differs from build by producing a self-contained, runnable layout, optionally for a specific runtime.
What it does
dotnet publish builds the app and gathers the application, its dependencies, the runtime config, and (optionally) the .NET runtime itself into a single output directory suitable for deployment. The default is a framework-dependent publish unless you pass --self-contained with a runtime identifier.
Common usage
dotnet publish -c Release -o ./publish
dotnet publish -c Release -r linux-x64 --self-contained false
dotnet publish -c Release -r linux-x64 --self-contained trueOptions
| Flag | What it does |
|---|---|
| -c, --configuration <name> | Configuration, usually Release for publish |
| -o, --output <dir> | Output directory for the published app |
| -r, --runtime <rid> | Target runtime identifier, e.g. linux-x64, win-x64 |
| --self-contained <true|false> | Bundle the .NET runtime (true) or depend on an installed one (false) |
| --no-restore / --no-build | Skip restore/build if a prior step did them |
| -p:PublishSingleFile=true | Produce a single-file executable |
In CI
Pin -c Release and an explicit -o so later steps (docker build, artifact upload) read from a known path. When you pass -r, a restore step that did not target that RID needs to restore again, so either restore with the same -r or let publish do its own restore.
Common errors in CI
NETSDK1047 ("Assets file ... doesn't have a target for ... Ensure restore has run and ... a runtime identifier") means you published with -r but restored without it; add -r to restore or drop --no-restore. NETSDK1097 relates to disabling self-contained options incorrectly. MSB1003 ("Specify a project or solution") appears when the directory has multiple projects.