|
1 | 1 | --- |
2 | | -title: Install and manage NuGet packages with the dotnet CLI |
3 | | -description: See how to use the dotnet CLI to install, list, remove, and update NuGet packages. |
| 2 | +title: Install and Manage NuGet Packages with the dotnet CLI |
| 3 | +description: Find out how to use the dotnet command-line interface (CLI) to install, list, remove, and update NuGet packages in .NET projects. |
4 | 4 | author: mikejo5000 |
5 | 5 | ms.author: mikejo |
6 | | -ms.date: 03/03/2025 |
7 | | -ms.topic: install-set-up-deploy |
| 6 | +ms.date: 04/17/2026 |
| 7 | +ms.topic: how-to |
| 8 | +# customer intent: As a developer, I want to find out how to use the dotnet CLI to manage NuGet packages so that I can use the packages in .NET projects. |
8 | 9 | --- |
9 | 10 |
|
10 | 11 | # Install and manage NuGet packages with the dotnet CLI |
11 | 12 |
|
12 | | -You can use the dotnet 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. |
| 13 | +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. |
13 | 14 |
|
14 | | -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](/dotnet/core/project-sdk/overview). |
| 15 | +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](/dotnet/core/project-sdk/overview). |
15 | 16 |
|
16 | | -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](../reference/dotnet-commands.md). |
| 17 | +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](../reference/dotnet-Commands.md). |
17 | 18 |
|
18 | 19 | ## Prerequisites |
19 | 20 |
|
20 | | -- The [.NET Core SDK](https://www.microsoft.com/net/download/), which provides the `dotnet` command-line tool. Starting in Visual Studio 2017, the dotnet CLI automatically installs with all .NET and .NET Core related workloads. |
| 21 | +The [.NET SDK](https://dotnet.microsoft.com/download), which provides the dotnet CLI. In Visual Studio, the dotnet CLI automatically installs with all .NET-related workloads. |
21 | 22 |
|
22 | 23 | ## Install or update a package |
23 | 24 |
|
24 | | -The [dotnet add package](/dotnet/core/tools/dotnet-add-package) command adds a package reference to the project file, and then runs `dotnet restore` to install the package. |
| 25 | +The [dotnet package add](/dotnet/core/tools/dotnet-package-add) command adds a package reference to the project file, and then runs `dotnet restore` to install the package. |
25 | 26 |
|
26 | | -1. Open a command line and switch to the directory that contains your project file. |
| 27 | +1. Open a command-line window and go to the directory that contains your project file. |
27 | 28 |
|
28 | 29 | 1. Use the following command to install a NuGet package: |
29 | 30 |
|
30 | | - ```dotnetcli |
31 | | - dotnet add package <PACKAGE_NAME> |
32 | | - ``` |
| 31 | + ```dotnetcli |
| 32 | + dotnet package add <package-name> |
| 33 | + ``` |
33 | 34 |
|
34 | | - For example, to install the `Newtonsoft.Json` package, use the following command |
| 35 | + For example, to install the `Newtonsoft.Json` package, use the following command: |
35 | 36 |
|
36 | | - ```dotnetcli |
37 | | - dotnet add package Newtonsoft.Json |
38 | | - ``` |
| 37 | + ```dotnetcli |
| 38 | + dotnet package add Newtonsoft.Json |
| 39 | + ``` |
39 | 40 |
|
40 | | -1. After the command completes, you can open the project file to see the package reference. |
| 41 | + If you're using .NET 9 or earlier, use the verb-first form of the command instead: |
41 | 42 |
|
42 | | - For example, open the *.csproj* file to see the added `Newtonsoft.Json` package reference: |
| 43 | + ```dotnetcli |
| 44 | + dotnet add package <package-name> |
| 45 | + ``` |
43 | 46 |
|
44 | | - ```xml |
45 | | - <ItemGroup> |
46 | | - <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> |
47 | | - </ItemGroup> |
48 | | - ``` |
| 47 | +1. After the command finishes, open the project file to check for the package reference. |
| 48 | + |
| 49 | + For example, open the *.csproj* file and check for the added `Newtonsoft.Json` package reference: |
| 50 | + |
| 51 | + ```xml |
| 52 | + <ItemGroup> |
| 53 | + <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> |
| 54 | + </ItemGroup> |
| 55 | + ``` |
49 | 56 |
|
50 | 57 | ## Install a specific version of a package |
51 | 58 |
|
52 | | -The `dotnet add package` command installs the latest version of the package unless you specify a different version. |
| 59 | +The `dotnet package add` command installs the latest version of the package unless you specify a different version. |
53 | 60 |
|
54 | 61 | To install a specific version of a NuGet package, use the optional `-v` or `--version` switch: |
55 | 62 |
|
56 | 63 | ```dotnetcli |
57 | | -dotnet add package <PACKAGE_NAME> -v <VERSION> |
| 64 | +dotnet package add <package-name> -v <version> |
58 | 65 | ``` |
59 | 66 |
|
60 | | -For example, to add version 12.0.1 of the `Newtonsoft.Json` package, use this command: |
| 67 | +For example, to add version 13.0.1 of the `Newtonsoft.Json` package, use this command: |
61 | 68 |
|
62 | 69 | ```dotnetcli |
63 | | -dotnet add package Newtonsoft.Json --version 12.0.1 |
| 70 | +dotnet package add Newtonsoft.Json --version 13.0.1 |
64 | 71 | ``` |
65 | 72 |
|
66 | 73 | ## List package references |
67 | 74 |
|
68 | | -List the package references and versions for your project by using the [dotnet list package](/dotnet/core/tools/dotnet-list-package) command: |
| 75 | +You can use the [dotnet package list](/dotnet/core/tools/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: |
| 76 | + |
| 77 | +```dotnetcli |
| 78 | +dotnet package list |
| 79 | +``` |
| 80 | + |
| 81 | +If you're using .NET 9 or earlier, use the verb-first form instead: |
69 | 82 |
|
70 | 83 | ```dotnetcli |
71 | 84 | dotnet list package |
72 | 85 | ``` |
73 | 86 |
|
74 | 87 | ## Remove a package |
75 | 88 |
|
76 | | -Use the [dotnet remove package](/dotnet/core/tools/dotnet-remove-package) command to remove a package reference from the project file. |
| 89 | +You can use the [dotnet package remove](/dotnet/core/tools/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: |
77 | 90 |
|
78 | 91 | ```dotnetcli |
79 | | -dotnet remove package <PACKAGE_NAME> |
| 92 | +dotnet package remove <package-name> |
80 | 93 | ``` |
81 | 94 |
|
82 | 95 | For example, to remove the `Newtonsoft.Json` package, use the following command: |
83 | 96 |
|
84 | 97 | ```dotnetcli |
85 | | -dotnet remove package Newtonsoft.Json |
| 98 | +dotnet package remove Newtonsoft.Json |
| 99 | +``` |
| 100 | + |
| 101 | +If you're using .NET 9 or earlier, use the verb-first form instead: |
| 102 | + |
| 103 | +```dotnetcli |
| 104 | +dotnet remove package <package-name> |
86 | 105 | ``` |
87 | 106 |
|
88 | 107 | ## Restore packages |
89 | 108 |
|
90 | 109 | [!INCLUDE [restore-dotnet-cli](includes/restore-dotnet-cli.md)] |
91 | 110 |
|
92 | | -## Next steps |
| 111 | +## Related content |
93 | 112 |
|
94 | 113 | - [.NET CLI overview](/dotnet/core/tools) |
95 | 114 | - [Install and manage packages in Visual Studio using the NuGet Package Manager](install-use-packages-visual-studio.md) |
96 | | -- [Install and manage packages with the Package Manager Console](install-use-packages-powershell.md) |
| 115 | +- [Manage packages with the Visual Studio Package Manager Console (PowerShell)](install-use-packages-powershell.md) |
0 commit comments