.NET Restore vs Build: What's the Difference?
When a .NET project behaves unexpectedly, developers often run dotnet restore, dotnet build, or dotnet clean without knowing exactly what each command does. They are related, but they solve different problems.
This guide explains what each command does, when to use it, and how the commands work together during normal .NET development.
π What Does dotnet restore Do?
dotnet restore resolves the NuGet dependencies declared by your project and downloads the packages required for the build.
dotnet restore
For example, if your project contains:
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
restore makes sure the required package and its dependency graph are available locally.
Restore is mainly about dependencies
- Reads project and package information.
- Resolves direct and transitive dependencies.
- Downloads missing NuGet packages.
- Creates or updates the assets information used by the build.
ποΈ What Does dotnet build Do?
dotnet build compiles your project or solution.
dotnet build
The build process uses the resolved dependencies and compiles your C# source files into assemblies and other build outputs.
In a normal project, running dotnet build may also trigger restore automatically when the required restore information is missing or outdated.
π§Ή What Does dotnet clean Do?
dotnet clean removes generated build output such as files under the project's bin and obj directories.
dotnet clean
It does not mean βdelete every NuGet package.β It primarily removes generated build artifacts so the next build can start from a cleaner state.
π Restore vs Build vs Clean
| Command | Main purpose |
|---|---|
dotnet restore | Resolve and download NuGet dependencies |
dotnet build | Compile the project |
dotnet clean | Remove generated build output |
π§© A Typical Development Sequence
A common troubleshooting sequence is:
dotnet clean
dotnet restore
dotnet build
Each command has a separate responsibility:
- Clean removes stale build artifacts.
- Restore resolves the current dependency graph.
- Build compiles the source code using those dependencies.
β οΈ When Should You Run dotnet restore?
Restore is particularly useful after changing package references, cloning a project to a new computer, deleting the obj directory, or encountering missing-package errors.
If the problem is a NuGet version conflict, inspect the dependency graph before repeatedly restoring. A restore cannot make incompatible package requirements compatible by itself.
For dependency troubleshooting, see π¦ Direct vs Transitive NuGet Dependencies.
π§ When Should You Run dotnet clean?
Use clean when old generated files may be interfering with a build, when you want to reproduce a clean build locally, or before packaging a project from scratch.
Cleaning is not normally necessary after every source-code change.
π» Useful Commands
# Restore dependencies
dotnet restore
# Build in Debug configuration
dotnet build
# Clean generated output
dotnet clean
# Clean and then restore and build
dotnet clean && dotnet restore && dotnet build
π§ Key Takeaway
Restore resolves dependencies, build compiles code, and clean removes generated build output.
Understanding this distinction makes .NET troubleshooting much easier because you can choose the command that actually addresses the problem instead of treating restore and build as interchangeable operations.
For more .NET tutorials, visit π .NET Tutorials.
Ask AlgoLassi and get an answer plus the tutorials worth studying next.
π¬ Comments
Sign in with Google to publish immediately, or comment anonymously and wait for approval.
Comments will appear here when available.