.NET Framework Documentation

Managing Dependencies with NuGet Packages

NuGet is the package manager for the .NET ecosystem. It is used to discover, install, and share reusable code and tools. This document explains how to work with NuGet packages within your .NET Framework projects.

What are NuGet Packages?

NuGet packages are essentially ZIP archives containing compiled code (DLLs), related files, and a manifest that describes the package. They provide a standardized way to integrate third-party libraries and frameworks into your .NET Framework applications.

Key benefits of using NuGet packages include:

How to Use NuGet Packages

You can manage NuGet packages using several tools:

1. Visual Studio NuGet Package Manager UI

Visual Studio provides a built-in graphical interface for managing packages:

  1. Right-click on your project in the Solution Explorer.
  2. Select "Manage NuGet Packages...".
  3. Browse or search for packages in the "Browse" tab.
  4. Select a package and click "Install".
  5. Review the license terms and accept to install.

Tip: The "Installed" tab shows packages already in your project, while "Updates" helps you keep packages current.

2. NuGet Package Manager Console

For command-line enthusiasts, the Package Manager Console (Tools > NuGet Package Manager > Package Manager Console) offers a powerful way to manage packages using PowerShell commands.

Common commands:

Install-Package <PackageName>
Update-Package <PackageName>
Uninstall-Package <PackageName>
Get-Package

For example, to install the popular Newtonsoft.Json package:

Install-Package Newtonsoft.Json

3. .NET CLI (Command Line Interface)

While the .NET CLI is more associated with .NET Core and later, it can also manage NuGet packages for .NET Framework projects.

dotnet add package <PackageName>

Best Practices for NuGet Packages