Beginner 9 min read

NuGet Package Manager: Install, Update, Restore, and Dependencies

Learn how NuGet manages packages in .NET projects, including installing and updating packages, restoring dependencies, and understanding transitive dependencies.

NuGet Package Manager: Install, Update, Restore, and Dependencies

Modern .NET applications rarely rely only on code written by their developers. They use reusable libraries for tasks such as database access, logging, validation, authentication, and testing. NuGet is the package management system for .NET that helps developers find, install, update, and manage these libraries.

For example, an ASP.NET Core application can use Entity Framework Core to communicate with a database without implementing all database-access functionality from scratch.

In this guide, you'll learn how NuGet works, how to manage packages using Visual Studio and the .NET CLI, and how to understand direct and transitive dependencies.

1. What Is NuGet?

NuGet is the package management ecosystem for .NET. It provides tools and package feeds that allow developers to distribute and consume reusable libraries.

A NuGet package is typically a .nupkg file containing compiled assemblies, metadata, and potentially other assets such as build files or content.

Common NuGet packages include:

  • Microsoft.EntityFrameworkCore for Entity Framework Core functionality.
  • Microsoft.EntityFrameworkCore.SqlServer for SQL Server integration with Entity Framework Core.
  • Serilog.AspNetCore for Serilog logging integration.
  • xunit for unit testing.

NuGet packages can be obtained from public feeds, such as NuGet.org, or from private feeds configured by an organization.

2. How to Install a NuGet Package

You can install packages through Visual Studio or the .NET CLI.

Method 1: Using Visual Studio

  1. Open your .NET project in Visual Studio.
  2. Right-click the project in Solution Explorer.
  3. Select Manage NuGet Packages.
  4. Search for the package you need.
  5. Select the appropriate package and version.
  6. Install it and review any prompts.

Visual Studio adds the package reference to the project file when appropriate.

Method 2: Using the .NET CLI

Open a terminal in the directory containing your project file and run:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer

This command adds a reference to the SQL Server provider package for Entity Framework Core, using a compatible version according to the tool's package-selection behavior.

You can specify a particular version:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 9.0.0

Choose a version compatible with your target framework and the other Entity Framework Core packages in your application.

Important: Package versions in examples are illustrative. Before installing a package, check its supported frameworks, dependencies, and compatibility with your project.

3. Where Are NuGet Dependencies Stored?

In modern .NET projects, package references are usually declared in the .csproj file using the PackageReference format.

For example:

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"
                    Version="9.0.0" />
</ItemGroup>

This entry tells NuGet that the project depends on the specified package version.

When you restore the project, NuGet resolves the package and its dependencies. For PackageReference projects, downloaded packages are normally stored in the global NuGet package cache, while the obj/project.assets.json file records the resolved dependency information used by the build.

You generally should not manually edit project.assets.json; it is generated during restore.

4. How to Restore NuGet Packages

Package restore downloads or resolves the dependencies required by your project so that it can build correctly.

Run this command from the directory containing your solution or project:

dotnet restore

To restore a specific project:

dotnet restore MyApp.csproj

Restore is commonly performed automatically by modern .NET tooling during operations such as dotnet build and dotnet run, when needed.

When Is Package Restore Needed?

Restore is particularly useful when:

  • You clone a repository onto a new machine.
  • Package references have changed.
  • Required packages are missing from the local cache.
  • You switch branches and the dependency configuration changes.
  • A build fails because dependencies have not been restored.

For example, after cloning an ASP.NET Core project from GitHub, you can run:

git clone https://github.com/username/MyDotNetApp.git
cd MyDotNetApp
dotnet restore
dotnet build

Replace the example repository address with the actual repository URL.

Remember: Restore resolves dependencies; it does not automatically update every package to its latest version.

5. How to Update a NuGet Package

Package updates can introduce bug fixes, performance improvements, new features, and security fixes. However, updates can also introduce breaking changes, so they should be tested.

Update a Package Using the .NET CLI

To change a package reference to a specific version, use:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 9.0.1

This updates the project's package reference to the requested version, provided that the version is available and compatible.

In modern SDK-style projects, dotnet add package is also the standard command for adding a new package reference. If the package already exists, the command updates the reference.

Check for Outdated Packages

You can identify package references with newer available versions by running:

dotnet list package --outdated

For a specific project:

dotnet list MyApp.csproj package --outdated

Review the results before updating. A newer package version is not necessarily the best choice if it is incompatible with your framework or other dependencies.

After updating packages, restore, build, and test your application:

dotnet restore
dotnet build
dotnet test

6. What Are Direct and Transitive Dependencies?

Understanding dependency types is essential when managing NuGet packages.

Direct Dependencies

A direct dependency is a package that your project explicitly references.

For example:

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Here, Newtonsoft.Json is a direct dependency because the project declares it explicitly.

Transitive Dependencies

A transitive dependency is a package required by another package in your dependency graph.

Suppose your project references Package A, and Package A depends on Package B. If your project does not explicitly reference Package B, it can still be resolved and included through Package A.

The relationship looks like this:

Your Project → Package A → Package B

In this example:

  • Package A is a direct dependency.
  • Package B is a transitive dependency.

NuGet resolves these dependencies so your application can use the required libraries without manually adding every dependency of every package.

Why Do Transitive Dependencies Matter?

Transitive dependencies can affect your application in several ways:

  • Different packages may depend on different versions of the same library.
  • A package update may change other resolved dependencies.
  • Vulnerabilities may exist in packages you never referenced directly.
  • Dependency conflicts can cause restore or build problems.

That is why reviewing the full dependency graph is an important part of maintaining a .NET application.

7. How to List NuGet Packages

Use the following command to list packages referenced by your project:

dotnet list package

To include transitive dependencies:

dotnet list package --include-transitive

The output helps you distinguish packages your project references directly from packages brought in through other dependencies.

To inspect packages with known vulnerabilities, use:

dotnet list package --vulnerable

The results depend on the SDK version, configured package sources, and available vulnerability information. Review the findings and update affected packages where appropriate.

8. Common NuGet Problems and Solutions

Package Restore Fails

Possible causes: Network problems, unavailable package feeds, authentication failures, or incompatible package requirements.

What to try:

dotnet nuget list source
dotnet restore

Check whether the required package source is enabled and accessible.

Package Version Conflict

Two packages may require incompatible versions of a shared dependency.

What to try:

  • Review the restore error and dependency graph.
  • Check package compatibility.
  • Align related package versions where required.
  • Update or replace incompatible packages.

Avoid changing versions blindly, because doing so may create additional conflicts.

Package Not Found

The requested package or version might not exist in the configured feeds, or the package source might be unavailable.

What to try:

  • Verify the package ID and version.
  • Check your configured NuGet sources.
  • Confirm that private feeds are accessible if the package is internal.

Vulnerable Package Detected

A package may have a known security vulnerability.

What to do:

  • Review the vulnerability details and affected versions.
  • Update to a supported, patched version where possible.
  • Check whether the dependency is direct or transitive.
  • Run your tests after making changes.

Do not ignore security warnings simply because the affected package is transitive.

9. Best Practices for NuGet Package Management

Follow these practices to keep your .NET projects reliable and maintainable:

  1. Choose compatible versions: Verify package compatibility with your target framework.
  2. Keep packages maintained: Review outdated and vulnerable dependencies regularly.
  3. Avoid unnecessary packages: Every dependency adds maintenance and potentially security considerations.
  4. Commit project files: Include .csproj files and applicable dependency-management files in source control.
  5. Restore before building when needed: Ensure dependencies are available, especially after cloning or changing package references.
  6. Test after updates: Run builds and automated tests to detect regressions.
  7. Review transitive dependencies: Do not assume packages are safe simply because you did not add them directly.
  8. Use trusted package sources: Verify package publishers and avoid installing unknown or suspicious packages.

Frequently Asked Questions

1. What is NuGet in .NET?

NuGet is the package management system for .NET. It allows developers to discover, install, update, restore, and distribute reusable libraries.

2. What is the difference between dotnet add package and dotnet restore?

dotnet add package adds or updates a package reference in the project file. dotnet restore resolves the project's dependencies and makes the required packages available for development and building.

3. What is a transitive dependency in NuGet?

A transitive dependency is a package required by another package your project references. NuGet resolves these indirect dependencies as part of the dependency graph.

4. Where are NuGet packages stored?

On most modern .NET installations, downloaded packages are stored in a global package cache. The default location is typically under the user's .nuget/packages directory, although the location can be configured.

5. Does dotnet restore update packages to their latest versions?

No. Restore resolves dependencies according to the project's package references and applicable dependency-resolution rules. Updating a package reference is a separate operation.

6. How can I check for vulnerable NuGet packages?

Run dotnet list package --vulnerable to identify packages with known vulnerabilities reported by the available package sources and tooling.

Conclusion

NuGet is a fundamental part of modern .NET development. By understanding package installation, updates, restore operations, and transitive dependencies, you can manage project libraries more confidently and troubleshoot dependency-related issues efficiently.

For professional .NET development, make package maintenance part of your workflow: review dependencies, investigate security warnings, and test your application after important updates.

Last updated 10/26/2026

Your notes

Sign in to save personal notes on this topic — they'll sync across your devices.

Was this tutorial helpful?

Help us create more free learning resources. Learn more

Make a Donation