Different ways to install a NuGet Package

NuGet packages are downloaded and installed using any of the following methods (see Install NuGet client tools if you don't have these installed already):

Method Description
dotnet.exe CLI
dotnet install <package_name>
(All platforms) Downloads the package identified by <package_name>, expands its contents into a folder in the current directory, and adds a reference to the project file. Also downloads and installs dependencies.
Package Manager UI (Visual Studio) (Windows and Mac) Provides a UI through which you can browse, select, and install packages and their dependencies into a project. Adds references to installed packages to the project file.
Package Manager Console (Visual Studio)
Install-Package <package_name>
(Windows only) Downloads and installs the package identified by <package_name> into a specified project in the solution, then adds a reference to the project file. Also downloads and installs dependencies.
nuget.exe CLI
nuget install <package_name>
(All platforms) Downloads the package identified by <package_name> and expands its contents into a folder in the current directory; can also download all packages listed in a packages.config file. Also downloads and installs dependencies, but makes no changes to project files.

General install process

In general, NuGet does the following then asked to install a package:

  1. Acquire the package:

    • Check if the requested package already exists in a cache (see Managing the NuGet cache).
    • If the package is not in the cache, attempt to download the package from the sources listed in the configuration files.
      • For projects using the packages.config reference format, NuGet uses the order of the sources in the configuration.
      • For projects using the PackageReference format, NuGet checks sources that are local folders first, then checks sources on network shares, then checks HTTP (Internet) sources.
      • In general, the order in which NuGet checks sources isn't particularly meaningful, because any given package with a specific identifier and version number is exactly the same on whatever source it's found.
    • If the package is successfully acquired from one of the sources, NuGet adds it to the cache. Otherwise, installation fails.
  2. Expand the package into the project.

    • Expanding means unzipping the package's contents into an appropriate subfolder. A copy of the .nupkg itself is also placed in the subfolder.
    • If the package is being installed into a Visual Studio or .NET Core project, only the files relevant to the project's target framework are expanded. When installed using the nuget.exe command line, all assemblies are expanded.
  3. If the package is installed within Visual Studio or the dotnet CLI, a reference is added to the appropriate project file (or packages.config for some project types in Visual Studio).