Home Nuget Restore vs Dotnet Restore in .NET Project

Nuget Restore vs Dotnet Restore in .NET Project

Restore NuGet Packages

Package Restore installs the direct dependencies of a project as needed and then installs any dependencies of those packages throughout the entire dependency graph.
Restore command only adds packages to the disk; it does not change a project’s dependencies. Nuget Restore keeps the dependency files in a cache location. To change a project’s dependencies, modify packages.config file then restore pacakages again.

Clear NuGet Packages

Clear NuGet packages is an action that removes already installed NuGet caches from the cache location.

Normally, NuGet Packages are installed from the cache location if one exists, otherwise it will be downloaded from the corresponding feed. Sometimes we need to clear the NuGet Packages when we encounter package installation problems or we just want to make sure packages have been installed and configured locally, it does not hurt to clear the NuGet Packages and restore them. NuGet Package Cache is store in %userprofile%\.nuget\packages, you can clear the NuGet Package manually by removing the files in the location. Alternatively, you could remove cache automatically through VS.

image-descripton %userprofile%.nuget\packages
Image above is the %userprofile%\.nuget\packages folder we talked about. We could delete files in the folder to clear NuGet Packages in our lcoal environment.


NuGet CLI tool allows you to easily update and restore NuGet packages in projects and solution. In order to use NuGet CLI, we must have the nuget.exe file. Most importantly, NuGet CLI requires a packages.config file for package references, and the file needs to be placed in the project location. To find out if you installed nuget.exe or figure out the version, you could use nuget ? v - command.
The screenshot above show NuGet CLI is installed in local environment and the version is

DotNet CLI

DonNet CLI allows you to do pretty much the same things as NuGet CLI does. On top of that, you can use DotNet CLI on Windows, Mac and Linux.

nuget restore vs dotnet restore

There are two ways of how NuGet packages are referenced in .NET project. nuget restore keeps the dependencies file in a cache location and dotnet restore keeps the file in Solution Folder


It is the classic way of referencing NuGet packages. It assumes NuGet is a separate tool and MSBuild doesn’t have any acknowledge of NuGet. nuget.exe (NuGet client) read through the packages.config file and downloads the referenced packages into a local folder on restore. nuget restore command only downloads the (packages) file, instead of modifying packages.config file.


Unlike packages.config, only the direct dependencies are listed. On restore via PackageReference, NuGet client (in this case, MSBuild items that reference a Nuget Package) figures out dependency graph by evaluating the direct and transitive (indirect) dependencies, and ensure packages are downloaded into user’s cache folder (in %userprofile%\.nuget\packages), and supply an assets file into the obj folder that contains a list of all packages and assets that the project users.


In my opinion, nuget restore downloads all of NuGet dependencies, where as dotnet restore is a complete restoration of NuGet dependencies as well as references and project specific tools.

This Blog Post Is Authorized by Author via CC BY 4.0
Post Menu


Goodbye Rocko