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-buildavoid repeating work in later steps.build,testandpublishwill 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."
More on .NET builds (dotnet CLI)
How do you build and run a .NET application?BeginnerWhat is the difference between .NET Framework and modern .NET?BeginnerWhat are .csproj and .sln files?BeginnerWhat is NuGet?BeginnerWhat is Kestrel?BeginnerHow does configuration work in ASP.NET Core (appsettings.json and environment variables)?Intermediate