Explain dotnet restore, build, test and publish.

BeginnerHands-on.NET builds (dotnet CLI)
Answer

Short answer

These four commands are the whole .NET build pipeline: restore downloads NuGet packages, build compiles the code, test runs unit tests, and publish produces a folder with everything needed to run the app — the deployable artifact.

Pipeline

dotnet restore Shop.sln
dotnet build Shop.sln -c Release --no-restore
dotnet test Shop.sln -c Release --no-build --logger "trx" --collect:"XPlat Code Coverage"
dotnet publish src/Shop.Api/Shop.Api.csproj -c Release -o ./out --no-build

What each produces

Command Output
restore obj/project.assets.json, packages in ~/.nuget/packages
build DLLs in bin/Release/net8.0/
test .trx test results + coverage files
publish ./out/ with Shop.Api.dll, dependencies, appsettings*.json

Notes

  • -c Release — optimised build. Debug is the default; never ship it.
  • --no-restore / --no-build avoid repeating work in later steps.
  • build, test and publish will restore automatically if you don't pass --no-restore.

What to say in the interview

"restore pulls packages, build compiles, test runs the test projects with trx and coverage output, and publish creates the deployable folder. In CI we run them in that order with -c Release and the no-restore/no-build flags to avoid duplicate work."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: .NET apps: dotnet build & publish

More on .NET builds (dotnet CLI)