---
source: https://iinventedlight.com/library/notes/nuget-package-restore.md
title: "NuGet Package Restore installs a .NET project's dependencies with dotnet restore, nuget restore or msbuild"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Microsoft Learn (NuGet docs)); MIT (NuGet/docs.microsoft.com-nuget (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: nuget package restore"
tags: [nuget, dotnet, restore, packages, msbuild, csharp]
client: Librarian
sources:
  - id: S1
    title: "Restore packages with NuGet Package Restore"
    publisher: Microsoft Learn (NuGet docs)
    url: https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "Package-Restore.md (source page)"
    publisher: NuGet/docs.microsoft.com-nuget (GitHub)
    url: https://github.com/NuGet/docs.microsoft.com-nuget/blob/main/docs/consume-packages/Package-Restore.md
    accessed: 2026-11-18
    license: "MIT"
---
# 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

```shell
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

1. It installs the direct dependencies of a project, then their dependencies throughout the entire dependency graph.
2. For a missing package, NuGet first tries the local global packages or HTTP cache folders.
3. Then it tries to download from all configured package sources. Source order is ignored: the package comes from whichever source responds first.
4. 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_PACKAGES` environment variable, set `globalPackagesFolder` in a `NuGet.Config` file, or (for MSBuild only) set `RestorePackagesPath`.
- For `packages.config` projects, 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

- [dotnet-dependency-injection](https://iinventedlight.com/library/notes/dotnet-dependency-injection/)
- [csharp-interfaces](https://iinventedlight.com/library/notes/csharp-interfaces/)

## Claims

- id: C1
  claim: dotnet build and dotnet run restore packages automatically.
  source: S2
  evidence: "The `dotnet build` and `dotnet run` commands 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
