Install and manage packages using the dotnet CLI

06/03/2019

2 minutes to read

In this article

The CLI tool allows you to easily install, uninstall, and update NuGet packages in projects and solutions. It runs on Windows, Mac OS X, and Linux.

The dotnet CLI is for use in your .NET Core and .NET Standard project (SDK-style project types), and for any other SDK-style projects (for example, an SDK-style project that targets .NET Framework). For more information, see SDK attribute.

This article shows you basic usage for a few of the most common dotnet CLI commands. For most of these commands, the CLI tool looks for a project file in the current directory, unless a project file is specified in the command (the project file is an optional switch). For a complete list of commands and the arguments you may use, see the .NET Core command-line interface (CLI) tools.

Remove a package

For example, to remove the Newtonsoft.Json package, use the following command

dotnet remove package Newtonsoft.Json

Update a package

NuGet installs the latest version of the package when you use the dotnet add package command unless you specify the package version (-v switch).

Restore packages

Use the dotnet restore command, which restores packages listed in the project file (see PackageReference). With .NET Core 2.0 and later, restore is done automatically with dotnet build and dotnet run. As of NuGet 4.0, this runs the same code as nuget restore.

As with the other dotnet CLI commands, first open a command line and switch to the directory that contains your project file.