skip to content

With the .NET 10 SDK, what do dotnet build, dotnet run and dotnet publish each produce, and which configuration does each use by default?

level: juniorimportance: must knowfreq 72%

answer

  1. compile vs launch vs deployable folder
  2. implicit restore before every verb
  3. bin/Debug/net10.0 vs .../publish
  4. PublishRelease defaults to true for net8.0+
  5. dotnet clean honours -c too

basics

~20 s

dotnet build compiles into bin/Debug/net10.0, dotnet run builds and then launches the app (also Debug), and dotnet publish writes the deployable set to a publish folder using Release by default for net8.0 and later projects.

solid answer

~40 s

All three restore implicitly first. `dotnet build` compiles the project and its references into `bin/<Configuration>/<TFM>/`, using `Debug` unless you pass `-c Release`. `dotnet run` builds if needed and then starts the app, so it is the inner-loop command and also defaults to `Debug`. `dotnet publish` runs the build and then copies everything the app needs to run elsewhere into a `publish` folder, applying publish-only settings such as a runtime identifier, self-contained, single-file or ReadyToRun. Since the .NET 8 SDK, `dotnet publish` on a `net8.0`+ project uses `Release` by default because the SDK sets `PublishRelease` to `true`, so `bin/Release/net10.0/publish/` is the default output. `dotnet clean` removes the outputs of one configuration, Debug unless told otherwise.

code

bash · 12 lines
bash
# Inner loop: Debug build, then launch
dotnet run --project src/PrintQueue

# Release build without publishing
dotnet build src/PrintQueue -c Release

# Deployable folder: Release by default on net10.0
dotnet publish src/PrintQueue
# -> src/PrintQueue/bin/Release/net10.0/publish/

# Clean the Release outputs (the default would clean Debug)
dotnet clean src/PrintQueue -c Release

go deeper

for a junior

Recall the three verbs and their outputs: build compiles, run builds and launches, publish produces the folder you deploy. Know that -c picks Debug or Release.

for a middle

Explain where each output lands, that every verb restores implicitly, and that PublishRelease makes publish default to Release for net8.0 and later targets.

for a senior

Show you write CI scripts that are explicit anyway: -c Release, -o for the artifact folder, --no-restore and --no-build to avoid repeated work between steps.

for a principal

Frame defaults as a supply-chain concern: a pipeline that depends on an implicit SDK default can change behaviour when the SDK or target framework moves, so standardize the switches in shared build scripts.

## Three verbs, three different outputs The `dotnet` driver turns a project file (`.csproj`) into something you can run. The three verbs every .NET developer uses daily are thin front-ends over **MSBuild targets**: | Command | What it does | Default configuration | Default output | |---|---|---|---| | `dotnet build` | restores, then compiles the project and its project references | `Debug` | `bin/Debug/net10.0/` | | `dotnet run` | restores and builds when needed, then launches the app | `Debug` | the same build output, then a running process | | `dotnet publish` | restores, builds, then copies the app and everything it needs into a deployable folder | `Release` for `net8.0`+ projects | `bin/Release/net10.0/publish/` | A **configuration** is a named set of build settings. `Debug` keeps optimizations off and full debugging information on; `Release` turns the compiler's optimizations on. You choose it with `-c` / `--configuration`. ## Why publish defaults to Release Before the .NET 8 SDK, every verb defaulted to `Debug`, and teams regularly shipped unoptimized builds because someone forgot `-c Release`. The SDK now sets the MSBuild property **`PublishRelease`** to `true` for any project whose target framework is `net8.0` or later, and the CLI reads it before the build starts. The result: on a `net10.0` project a plain `dotnet publish` produces `bin/Release/net10.0/publish/`. `dotnet build` and `dotnet run` still default to `Debug`, because they serve the inner development loop. A similar property, `PackRelease`, does the same for `dotnet pack` (owned by the packaging topic). You can still pass `-c Release` explicitly; it is harmless and makes a CI script readable regardless of target framework. ## What each output contains - **Build output** is runnable on the machine that built it: the app's `.dll`, an apphost executable for the current platform, the `.deps.json` and `.runtimeconfig.json` files, and the package assemblies the app references. - **Publish output** is the set you deploy. Publish is where runtime-specific choices happen: `-r` (runtime identifier), `--self-contained`, `PublishSingleFile`, `PublishReadyToRun`. With `-r linux-x64` the folder becomes `bin/Release/net10.0/linux-x64/publish/`. - `-o` / `--output` overrides the folder for either verb. ## Implicit restore and the other switches Each of these verbs runs a NuGet restore first unless you pass `--no-restore`, so adding a package and immediately running `dotnet run` works. Other common switches: 1. `-c Release` picks the configuration. 2. `-f net10.0` picks one framework in a multi-targeted project. 3. `-p:Name=Value` (also `--property`) sets any MSBuild property for this invocation only, for example `-p:Version=1.4.0`. 4. `--no-build` on `dotnet run` or `dotnet publish` reuses existing build output. ## Cleaning `dotnet clean` runs MSBuild's clean target: it deletes the files the previous build wrote to both `obj/` and `bin/` **for one configuration**. Because the default is `Debug`, cleaning after a Release build needs `dotnet clean -c Release`; otherwise the Release output stays. Deleting the `bin` and `obj` folders by hand is the blunt alternative when a build is confused. ## Starting a project `dotnet new console -n PrintQueue` creates the project from an installed template; `dotnet new install <package>` adds templates shipped as NuGet packages (it replaced the older `dotnet new --install` form, which still parses but is hidden). The inner loop is then `dotnet run`, and the release pipeline is `dotnet publish`. ## What interviewers listen for - That `run` builds first, so there is no separate compile step to remember. - That `publish`, not `build`, produces the deployment folder. - That the Release default for publish is a .NET 8 SDK change tied to the target framework, not a universal rule. ## Common mistakes - **Deploying the build folder.** `bin/Debug/net10.0/` runs on the developer's machine, but it is a Debug build and skips every publish-time step, so runtime-specific assets, single-file bundling and trimming never happen. - **Assuming every verb defaults to Release.** Only `publish` (and `pack`) changed; a CI step running `dotnet build` and then `dotnet test --no-build` without `-c Release` tests a Debug build. - **Mixing configurations between steps.** `dotnet build -c Release` followed by `dotnet publish --no-build` works only because publish also uses Release on `net8.0`+; on an older target framework the same script looks for Debug output and fails. - **Forgetting the target framework in paths.** Output folders include the TFM (`net10.0`), so a script that hard-codes `bin/Release/publish` breaks; pass `-o` instead of guessing paths. A short checklist answer in an interview: `run` for the inner loop, `build -c Release` to compile, `publish` for the artifact, `-o` to put it somewhere predictable.

  • How do you make dotnet publish use Debug on a net10.0 project?
    Pass `-c Debug` on the command line, or set `<PublishRelease>false</PublishRelease>` in the project file so the SDK stops defaulting publish to Release. The property is evaluated by the CLI before the build, so setting it in the project or a `Directory.Build.props` file works.
  • What does dotnet run --no-build do, and when does it bite?
    It skips the build and launches whatever output is already in `bin/<Configuration>/<TFM>/`. If you changed code since the last build, you run the stale binaries, and if the configuration you name was never built, the command fails because there is nothing to launch.
  • What does -o change on dotnet publish?
    `-o` (`--output`) sets the publish folder, which MSBuild knows as `PublishDir`, so the deployable files land where your pipeline expects them instead of under `bin/Release/<TFM>/publish/`.

  • dotnet publish on a net10.0 project still defaults to the Debug configuration.
  • dotnet run executes the files in the publish folder.
  • You must run dotnet restore before dotnet build or the build fails.
  • dotnet clean wipes the bin and obj output of every configuration at once.
  • dotnet build without -c builds Release because that is what CI needs.

Assumes the .NET 10 SDK and a net10.0 project; dotnet publish has defaulted to Release only since the .NET 8 SDK, and only for net8.0 or later targets.