skip to content

.NET CLI

The dotnet driver that scaffolds, builds, tests and publishes projects, installs .NET tools and selects the SDK through global.json. Interviewers probe it because every CI script runs on it.

on this pageshow

explore

questions

17

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.

open as a page

What is the difference between the .NET SDK and the .NET runtime, and what do dotnet --info, --list-sdks and --list-runtimes show?

level: juniorimportance: must knowfreq 55%

basics

~20 s

The .NET SDK is the toolchain (dotnet CLI, MSBuild, compilers, NuGet, templates) used to build apps; the runtime only runs them. dotnet --list-sdks and --list-runtimes print what is installed, and dotnet --info prints both plus the SDK selected for the current folder.

open as a page

With the .NET 10 SDK, how do global tools, tool-path tools and local tools differ in where they install and how you invoke them?

level: juniorimportance: must knowfreq 52%

basics

~20 s

A .NET tool is a console app shipped as a NuGet package; -g installs it per user into ~/.dotnet/tools on PATH, --tool-path into a folder you choose, and a local install records it in a repository's tool manifest, invoked through dotnet.

open as a page

With the .NET 10 SDK, how do dotnet publish -r, --self-contained, PublishSingleFile and PublishReadyToRun change what you ship for a command-line tool?

level: middleimportance: must knowfreq 60%

basics

~10 s

-r picks the target OS and CPU, --self-contained bundles the .NET runtime, PublishSingleFile packs the app into one executable, and PublishReadyToRun precompiles assemblies for faster startup; on net8.0+ a runtime identifier alone stays framework-dependent.

open as a page

How does global.json select the .NET SDK for a repository, and what happens with version 10.0.100 and no rollForward when only 10.0.400 is installed?

level: middleimportance: must knowfreq 50%

basics

~20 s

global.json pins the SDK with sdk.version, and without rollForward the policy is patch: use that version or a later patch in the same feature band. With 10.0.100 requested and only 10.0.400 installed, no 10.0.1xx SDK exists, so SDK resolution fails.

open as a page

How does a .NET tool manifest (dotnet-tools.json) pin tool versions for a team, and how does dotnet tool restore use it in CI with the .NET 10 SDK?

level: middleimportance: must knowfreq 48%

basics

~20 s

A tool manifest is a dotnet-tools.json file, normally .config/dotnet-tools.json at the repository root, listing each local tool's package id, exact version and commands; dotnet tool restore installs exactly those versions, so CI and every developer run the same tools.

open as a page

In a .NET 10 SDK pipeline, how do dotnet test's --filter and --logger options select tests and produce a results file?

level: middleimportance: should knowfreq 46%

basics

~20 s

dotnet test --filter takes expressions such as FullyQualifiedName~Pricing or Category!=Printer joined with | and &, and --logger trx writes a TRX results file into the TestResults folder; both are options of the default VSTest mode.

open as a page

When does dotnet watch hot reload a running .NET 10 app, and when does it rebuild and restart the app instead?

level: middleimportance: should knowfreq 40%

basics

~20 s

dotnet watch reruns dotnet run on every saved change and applies supported edits to the live process with hot reload; an edit it cannot apply (a rude edit) prompts for a restart, and --no-hot-reload or Ctrl+R forces a full restart.

open as a page

How does Directory.Build.props share MSBuild settings across a .NET solution, and why does a nested Directory.Build.props stop inheriting from the parent one?

level: middleimportance: should knowfreq 42%

basics

~20 s

MSBuild automatically imports the first Directory.Build.props it finds walking up from each project's folder, early in evaluation, so common properties live in one place. It stops at that first file, so a nested one must import its parent explicitly to keep inheriting.

open as a page

In an SDK-style .NET project, what is the difference between TargetFramework and TargetFrameworks, and how do the dotnet commands handle a multi-targeted project?

level: middleimportance: should knowfreq 45%

basics

~20 s

TargetFramework names the single framework a project builds for, such as net10.0; TargetFrameworks lists several, such as net8.0;net10.0, and the SDK builds once per framework. dotnet build and test cover every framework, while dotnet run needs -f to choose one.

open as a page

With the .NET 10 SDK, what do dotnet tool exec and the dnx script do, and when would you use them instead of installing a tool?

level: middleimportance: should knowfreq 22%

basics

~20 s

dotnet tool exec (alias of dotnet tool execute) downloads a tool package to the NuGet cache and runs it once without installing it or touching PATH; dnx is the shell script shortcut for the same command, added in the .NET 10 SDK.

open as a page

With the .NET 10 SDK, how does dotnet run app.cs build a file-based app, and what do its #:package, #:sdk, #:property and #:project directives do?

level: seniorimportance: should knowfreq 36%

basics

~20 s

dotnet run app.cs generates a virtual project from the file's #: directives, builds it into a cached temp folder and runs it; #:package adds a NuGet reference, #:sdk picks the project SDK, #:property sets an MSBuild property and #:project references a project.

open as a page

Which global.json rollForward policy suits a team repository, and what do allowPrerelease and the .NET 10 paths, errorMessage and test.runner settings add?

level: seniorimportance: should knowfreq 34%

basics

~10 s

Teams usually pin a version with rollForward latestFeature (newest 10.0 band) or latestPatch (one band); disable demands an exact SDK. The .NET 10 SDK adds paths for repository-local SDKs, errorMessage and test.runner.

open as a page

With the .NET 10 SDK, how do .sln and .slnx solution files differ, and how would you move a 40-project solution to .slnx with dotnet sln migrate?

level: seniorimportance: should knowfreq 32%

basics

~20 s

.sln is the old line-based format full of GUIDs and configuration sections; .slnx is a short XML file listing projects and folders. dotnet sln App.sln migrate writes App.slnx next to the original, after which you switch every reference and delete the .sln.

open as a page

A pinned local .NET tool fails on a CI agent that only has the .NET 10 runtime; how do dotnet tool update and --allow-roll-forward help?

level: seniorimportance: should knowfreq 24%

basics

~20 s

A framework-dependent tool needs the runtime it targets; either update the manifest to a tool version built for .NET 10 with dotnet tool update, or install it with --allow-roll-forward so the manifest records rollForward: true and the tool runs on the newer runtime.

open as a page

In a .NET 10 CI pipeline, how do dotnet format --verify-no-changes and dotnet build -p switches enforce code style, warnings and version stamps?

level: seniorimportance: nice to knowfreq 28%

basics

~10 s

dotnet format --verify-no-changes checks the code against .editorconfig and exits non-zero if it would change anything, and -p:Name=Value sets MSBuild properties such as TreatWarningsAsErrors=true or Version=1.4.0 for that build only.

open as a page

How do you turn a .NET 10 console project into an installable .NET tool with PackAsTool and ToolCommandName, and what changed for RID-specific tools?

level: seniorimportance: nice to knowfreq 16%

basics

~20 s

Set PackAsTool to true in an Exe project and optionally ToolCommandName; dotnet pack then builds a NuGet package of type DotnetTool that dotnet tool install accepts. In .NET 10, RuntimeIdentifiers or ToolPackageRuntimeIdentifiers produce RID-specific tool packages.

open as a page