When you run dotnet restore MyApp.sln from the folder containing that solution file, the .NET CLI reads every project the solution references and restores their dependencies into the global packages folder. The key condition is simple: point the command at the .sln file (or let it auto-detect one if only a single solution sits in the current directory), and the SDK handles the project graph for you. That single command replaces the older habit of restoring project-by-project. Everything below explains the mechanics, the flags that matter, the failure modes, and how restore fits into a build pipeline before you compile.

What dotnet restore actually does to a solution

Restore is the dependency-resolution phase of a .NET build. It reads each project's SDK-style project file, works out the target frameworks, follows ProjectReference links, and downloads the NuGet packages those projects declare into a shared package cache (by default under your user profile). It also writes an assets file (project.assets.json) into each project's obj folder. That assets file is what the compiler consults later, so a build without a successful restore will either fail or silently use stale inputs.

When the input is a solution file, the CLI doesn't restore "the solution" as a single unit. It opens the .sln document, enumerates the projects listed inside, filters out ones that aren't restorable (solution folders, for instance, or project types the SDK doesn't recognize), and restores the rest. This matters because the set of projects in a solution is often broader than the set you actually build; a CI script that restores the solution restores test projects and sample apps too, which changes timing and network usage.

A practical consequence: restore accuracy depends on the solution file being in sync with the projects on disk. If a project was added to the folder but never added to the solution, restoring the solution won't touch it. That's one of the most common "why is this project missing packages" causes.

Prerequisites before the first restore

You need the .NET SDK installed and on your PATH. Check it with dotnet --version; the printed version should be at least the target framework your projects declare. A project targeting a newer framework than your installed SDK supports will fail at restore or build with a clear framework error.

You also need network access to your configured NuGet feeds unless packages are already cached or you're restoring from a local/offline feed. For private feeds, credentials must be configured in advance (typically through a nuget.config at the repo or user level, or an environment-based token source). Restore is where those credentials get exercised, so a misconfigured feed surfaces here first.

Finally, confirm which file is the solution. Solution files end in .sln; newer SDK versions also understand the XML-based .slnx format. If the directory has several solutions, name the one you want explicitly rather than relying on auto-detection. Run dotnet sln list against the file to see the projects it contains before you restore.

The core procedure, step by step

1: Open a terminal in the directory that holds the solution file, or note the relative path to it if you're elsewhere. 2: Verify the solution contents with dotnet sln MyApp.sln list. This prints the projects the restore will consider. If something's missing, add it first with dotnet sln MyApp.sln add path/to/Project.csproj. 3: Run the restore: dotnet restore MyApp.sln. Add flags only as needed (covered below). Expect a line-by-line progress output and, on success, a "Restored" summary or a quiet exit. 4: Check the exit code. Restore returns 0 on success and non-zero on failure, which is what your scripts should test. You can inspect each project's obj/project.assets.json timestamp to confirm it was regenerated. 5: Proceed to dotnet build MyApp.sln --no-restore if you want to guarantee the build uses the restored state. This is the standard two-phase pattern in CI.

Success looks like a clean exit with no NU-prefixed errors. Failure is usually a non-zero code plus an error line naming the package, feed, or framework that broke.

Flags that change restore behavior on a solution

--no-cache forces restore to ignore the local HTTP cache and re-fetch from feeds, useful when you suspect a stale or corrupted cached package. --force re-evaluates dependencies even if the assets file looks current, which helps after editing package versions or NuGet config. --disable-parallel restores projects one at a time, a slower but more diagnosable mode when parallel restores produce confusing interleaved errors.

--source (or -s) overrides the configured feeds for this run, handy for pointing at a mirror or an offline folder. --packages redirects the global packages folder, which you might use to keep a build isolated. --configfile points at a specific nuget.config instead of the discovered one. For verbosity, -v normal or -v detailed shows the feed requests and resolution steps; -v diag is very noisy but occasionally necessary for credential or proxy problems.

One flag worth naming precisely: --runtime restores assets for a specific runtime identifier (RID) so that runtime-specific packages are present. If your solution includes projects that publish for a particular platform, restoring with the matching RID avoids a second restore at publish time. The exact set of supported flags and their spelling can drift across SDK versions, so run dotnet restore --help against your installed SDK to confirm before scripting.

Solution versus project restore, and where the solution earns its keep

Restoring a project (dotnet restore MyProject.csproj) resolves that project plus everything it references transitively. Restoring a solution resolves every restorable project listed in it, which can be more (independent apps, benchmarks, integration tests) or effectively the same (if the solution is just a wrapper over one root project and its references).

The solution wins when you want one consistent package graph across all projects in a repo and a single command that CI can call. It's also the natural target for dotnet build and dotnet test at the solution level, since you'll usually follow restore with one of those. The project wins when you're iterating on a single library and want a faster loop, or when a solution contains projects that intentionally need different feeds or settings.

A fair comparison uses the same working directory, same SDK version, and a warm package cache; under those conditions solution restore mainly costs extra time proportional to the number of projects that aren't already restored. On a cold cache, both pay the download cost, and the solution pays it for a larger set. Neither is "correct" in the abstract; the solution is the safer default for whole-repo operations.

Situation Restore target Why
CI building the whole repo The .sln file One graph, one exit code, matches build/test scope
Editing one library locally That .csproj Faster loop, fewer unrelated failures
Solution has projects needing separate feeds Individual projects or a filtered solution Avoid applying one feed config to all
New project added to folder but not solution Add to solution first Solution restore ignores unlisted projects

Common failures and how to read them

The NU1101 family means a package couldn't be found on any configured feed; check spelling, version existence, and whether the right feed is in nuget.config. Authentication-shaped failures often appear as 401 or a credential-provider prompt; the fix is usually in feed credentials, not in the restore command. NU1301 typically signals an unreachable source or network/proxy problem. Framework mismatches surface as messages about the target framework not being supported by the installed SDK.

A subtler class: restore succeeds but the build then complains about missing references or stale assets. That usually means the object folders were deleted or a different configuration (Debug vs. Release, or a different RID) has its own assets expectations. Running restore again against the same solution with the intended configuration resolves it. If a solution file references a project path that no longer exists, the CLI reports it during enumeration; fix the solution with dotnet sln remove/add rather than hand-editing unless you're comfortable with the format.

Start troubleshooting with reversible checks: re-run with -v normal, try --no-cache, confirm the solution's project list, then confirm feed configuration. Only move to --disable-parallel or diagnostic logging once the simpler checks rule out the obvious. If a private feed's authentication requires organizational credentials you don't hold, that's the stop point—loop in whoever administers the feed rather than embedding secrets in scripts.

Putting restore into scripts and CI

The reliable pattern is: check out code, install or select the SDK version pinned by the repo (common via a global.json), run dotnet restore MyApp.sln, then dotnet build MyApp.sln --no-restore, then tests with --no-build. Using --no-restore and --no-build downstream prevents silent re-restores and makes failures attributable to the right phase.

Pin the SDK with global.json if your team needs reproducibility; otherwise a machine with a newer SDK may resolve packages or target frameworks differently. For locked dependency graphs, enable lock files in the project (a packages.lock.json per project) and restore in locked mode so that CI fails when the graph would change—this trades flexibility for determinism. The exact property and flag names for lock files have changed across SDK generations, so confirm against your installed SDK's documentation before relying on them.

Keep credentials out of the solution file and out of committed config; use environment-provided tokens or a credential provider. And treat restore warnings (deprecations, version conflicts) as signal—they're cheapest to fix here, before they become build failures.

Edge cases worth knowing

Multi-targeting projects restore assets for every target framework listed, so restore time scales with framework count. Projects with conditional PackageReference items restore differently per configuration, which means a Release restore can legitimately pull packages a Debug restore didn't. Solution folders and certain non-buildable project types are skipped, so a solution that "contains" a project type the SDK doesn't handle won't restore it. And if you keep multiple solutions in one repo that overlap in projects, restoring each is fine, but the shared package cache means later restores are cheap.

For .slnx files, the same command shape applies (dotnet restore MyApp.slnx) on SDK versions that support the format; on older SDKs, the file simply won't be recognized, so check your version. Offline builds work when every needed package is already in the global cache or a local feed specified with --source.

FAQ

Does dotnet build restore automatically? Yes, by default build implies restore unless you pass --no-restore. The explicit two-step pattern is still preferred in CI for clearer failure attribution.

Can I restore only some projects in the solution? Not through a single solution-level filter in the base command; restore the specific projects instead, or maintain a smaller solution for that subset.

Why did restore succeed but the build still fail on a missing package? Usually a stale or partial assets file, a different configuration/RID, or object folders that were cleaned; re-run restore for the exact configuration you're building.