Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can use the dotnet command-line interface (CLI) tool on Windows, macOS, or Linux to easily install, uninstall, and update NuGet packages in .NET projects and solutions. This article describes the most common dotnet CLI commands for managing NuGet packages.
The dotnet CLI runs on .NET, .NET Core, .NET Standard SDK-style projects, and any other SDK-style projects, for example, those that target .NET Framework. For more information, see .NET project SDKs.
For most commands, the CLI tool looks for a project file in the current directory, unless a different project file is specified as an optional switch in the command. For a complete list of commands and their arguments, see dotnet CLI commands.
Prerequisites
The .NET SDK, which provides the dotnet CLI. In Visual Studio, the dotnet CLI automatically installs with all .NET-related workloads.
Install or update a package
The dotnet package add command adds a package reference to the project file, and then runs dotnet restore to install the package.
Open a command-line window and go to the directory that contains your project file.
Use the following command to install a NuGet package:
dotnet package add <package-name>For example, to install the
Newtonsoft.Jsonpackage, use the following command:dotnet package add Newtonsoft.JsonIf you're using .NET 9 or earlier, use the verb-first form of the command instead:
dotnet add package <package-name>After the command finishes, open the project file to check for the package reference.
For example, open the .csproj file and check for the added
Newtonsoft.Jsonpackage reference:<ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> </ItemGroup>
Install a specific version of a package
The dotnet package add command installs the latest version of the package unless you specify a different version.
To install a specific version of a NuGet package, use the optional -v or --version switch:
dotnet package add <package-name> -v <version>
For example, to add version 13.0.1 of the Newtonsoft.Json package, use this command:
dotnet package add Newtonsoft.Json --version 13.0.1
List package references
You can use the dotnet package list command to list the package references and versions for your project. From the directory that contains your project file, run the following command:
dotnet package list
If you're using .NET 9 or earlier, use the verb-first form instead:
dotnet list package
Remove a package
You can use the dotnet package remove command to remove a package reference from the project file. From the directory that contains your project file, run the following command:
dotnet package remove <package-name>
For example, to remove the Newtonsoft.Json package, use the following command:
dotnet package remove Newtonsoft.Json
If you're using .NET 9 or earlier, use the verb-first form instead:
dotnet remove package <package-name>
Restore packages
The dotnet restore command restores packages that are listed in <PackageReference> elements in the project file. For more information, see PackageReference in project files.
Starting with .NET Core 2.0 and continuing through .NET, the dotnet build and dotnet run commands restore packages automatically, as do many other dotnet CLI commands. As of NuGet 4.0, dotnet restore runs the same code as the nuget restore NuGet CLI command.
To restore packages by using dotnet restore:
- Open a command-line window and go to the directory that contains your project file.
- Run
dotnet restore.