Difference between dotnet Restore, Build & Run ( 01-D)


Some developers struggle to understand what happens when you run these 3 commands. Understanding the difference let you made better decisions during the development workflow especially when creating a CI/CD pipeline to ship your code into different environment.
Dotnet Restore :
Downloads all the external packages (NuGet packages) your project depends on. Think of it like , Checking your shopping list and downloading everything from the store before you start cooking
What it does:
Reads your
.csproj
orpackages.config
Connects to NuGet
Downloads the required packages into your local machine (usually in
~/.nuget/packages/
)Usually happens automatically with
dotnet build
in .NET Core and later versions
Dotnet Build :
Compiles your project source code into a
.dll
or.exe
file. Think of it like, Cooking the meal using the ingredients you got from the store.What it does:
Runs the compiler (Roslyn)
Turns your
.cs
files into IL (Intermediate Language)Outputs into the
/bin/Debug
or/bin/Release
folder
Dotnet Run
The
dotnet run
command builds and immediately executes your .NET application. Think of it like pressing the "Play" button in Visual Studio — your app compiles and launchesWhat Happens When You Run
It performs these steps under the hood:
Restores NuGet packages (if needed)
Builds the project (compiles code)
Runs the app
Subscribe to my newsletter
Read articles from Olayinka U. Kareem directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
