NuGet Package Restore installs a .NET project's dependencies with dotnet restore, nuget restore or msbuild
Answer: Run dotnet restore, nuget restore or msbuild -t:restore; dotnet build and dotnet run restore automatically. Package Restore restores all dependencies listed in a project file (<PackageReference>) or a packages.config file, so package binaries need not be stored in source control.
Commands
dotnet restore
dotnet add package Newtonsoft.Json # adds the reference and runs restore
nuget restore MySolution.sln
msbuild -t:restore
msbuild -restore # restore then build in one step
nuget locals http-cache -clear
How restore resolves packages
- It installs the direct dependencies of a project, then their dependencies throughout the entire dependency graph.
- For a missing package, NuGet first tries the local global packages or HTTP cache folders.
- Then it tries to download from all configured package sources. Source order is ignored: the package comes from whichever source responds first.
- If restore fails, NuGet reports a failure for only the last source, after checking all sources.
Configuration
- To use a different global packages folder, set the
NUGET_PACKAGESenvironment variable, setglobalPackagesFolderin aNuGet.Configfile, or (for MSBuild only) setRestorePackagesPath. - For
packages.configprojects, MSBuild restore needs-p:RestorePackagesConfig=true. - Visual Studio can be configured to restore packages automatically when it builds a project.
Why it matters
Package Restore promotes a cleaner development environment and reduces repository size, because a project's dependencies are available without storing them in source control.
See also
Claims
- id: C1 claim: dotnet build and dotnet run restore packages automatically. source: S2 evidence: "The
dotnet buildanddotnet runcommands automatically restore packages"
- id: C2 claim: NuGet ignores the order of package sources. source: S2 evidence: "During restore, NuGet ignores the order of package sources"
- id: C3 claim: NuGet first tries the local global packages or HTTP cache. source: S1 evidence: "NuGet first attempts to retrieve it from the local"
Sources
- [S1] Restore packages with NuGet Package Restore. Microsoft Learn (NuGet docs). https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore . License: MIT. Accessed 2026-11-18.
- [S2] Package-Restore.md (source page). NuGet/docs.microsoft.com-nuget (GitHub). https://github.com/NuGet/docs.microsoft.com-nuget/blob/main/docs/consume-packages/Package-Restore.md . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (NuGet docs), Restore packages with NuGet Package Restore; NuGet/docs.microsoft.com-nuget (GitHub), Package-Restore.md (source page). MIT (https://raw.githubusercontent.com/NuGet/docs.microsoft.com-nuget/main/LICENSE). Copyright .NET Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (NuGet docs), Restore packages with NuGet Package Restore; NuGet/docs.microsoft.com-nuget (GitHub), Package-Restore.md (source page). MIT (https://raw.githubusercontent.com/NuGet/docs.microsoft.com-nuget/main/LICENSE). Copyright .NET Foundation.
Cite this
iinventedlight. 2026. "NuGet Package Restore installs a .NET project's dependencies with dotnet restore, nuget restore or msbuild." iinventedlight Library, iil:note:5rt5tdyc, version of 2026-11-18. https://iinventedlight.com/library/notes/nuget-package-restore/. License: CC-BY-4.0.
@misc{iil_note_5rt5tdyc,
author = {{iinventedlight}},
title = {{NuGet Package Restore installs a .NET project's dependencies with dotnet restore, nuget restore or msbuild}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/nuget-package-restore/},
note = {Permanent ID iil:note:5rt5tdyc. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/nuget-package-restore.md.