You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Install and use a NuGet package with the dotnet CLI
3
-
description: Get a quick tutorial on how to use the dotnet CLI to install and use a NuGet package in a .NET project.
2
+
title: Install and Use a NuGet Package with the dotnet CLI
3
+
description: In this quickstart, find out how to use the dotnet command-line interface (CLI) to install and use a NuGet package in a .NET project.
4
4
author: JonDouglas
5
5
ms.author: jodou
6
-
ms.date: 03/03/2025
6
+
ms.date: 04/17/2026
7
7
ms.topic: quickstart
8
+
# customer intent: As a developer, I want to find out how to use the dotnet CLI to install and use a NuGet package in a .NET project so that I can take advantage of available code.
8
9
---
9
10
10
11
# Quickstart: Install and use a package with the dotnet CLI
11
12
12
-
In this quickstart, you install the popular [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json) NuGet package into a .NET project by using the [dotnet add package](/dotnet/core/tools/dotnet-add-package) command. NuGet packages contain compiled binary code that developers make available for other developers to use in their projects. For more information, see [What is NuGet](../What-is-NuGet.md).
13
+
In this quickstart, you install the popular [`Newtonsoft.Json`](https://www.nuget.org/packages/Newtonsoft.Json) NuGet package into a .NET project. NuGet packages contain compiled binary code that developers make available for other developers to use in their projects. For more information, see [An introduction to NuGet](../what-is-nuget.md).
13
14
14
-
You refer to installed packages in code with a `using <namespace>` directive, where `<namespace>`is often the package name. You can then use the package's API in your project.
15
+
To install the package, you use the [dotnet package add](/dotnet/core/tools/dotnet-package-add) command, which is part of the dotnet command-line interface (CLI).
15
16
16
17
> [!Tip]
17
-
> Browse [nuget.org/packages](https://nuget.org/packages) to find packages you can reuse in your own applications. You can search directly at [https://nuget.org](https://nuget.org/packages), or you can find and install packages from within Visual Studio. For more information, see [Find and evaluate NuGet packages for your project](../consume-packages/finding-and-choosing-packages.md).
18
+
> Browse [nuget.org/packages](https://www.nuget.org/packages) to find packages you can reuse in your own applications. You can search directly at [https://nuget.org](https://www.nuget.org/packages), or you can find and install packages from within Visual Studio. For more information, see [Find and evaluate NuGet packages for your project](../consume-packages/Finding-and-Choosing-Packages.md).
18
19
19
20
## Prerequisites
20
21
21
22
- Visual Studio 2026. You can install the 2026 Community edition for free from [visualstudio.microsoft.com](https://visualstudio.microsoft.com/), or you can use the Professional or Enterprise edition.
22
-
- The [.NET SDK](https://www.microsoft.com/net/download), which provides the `dotnet` command-line interface (CLI). In Visual Studio, the dotnet CLI automatically installs with any .NET-related workloads.
23
+
- The [.NET SDK](https://dotnet.microsoft.com/download), which provides the dotnetCLI. In Visual Studio, the dotnet CLI automatically installs with any .NET-related workloads.
23
24
24
25
## Create a project
25
26
@@ -31,88 +32,94 @@ You can install NuGet packages into a .NET project. For this quickstart, take th
31
32
32
33
1. Create the project by using the following command:
33
34
34
-
```dotnetcli
35
-
dotnet new console
36
-
```
35
+
```dotnetcli
36
+
dotnet new console
37
+
```
37
38
38
-
1. Use `dotnet run` to test the app. You should see the output `Hello, World!`.
39
+
1. Use `dotnet run` to test the app. The command writes the following output to the screen:`Hello, World!`.
39
40
40
41
## Add the Newtonsoft.Json NuGet package
41
42
42
-
1. Use the following command to install the `Newtonsoft.json` package:
43
+
1. Use the following command to install the `Newtonsoft.Json` package:
43
44
44
-
```dotnetcli
45
-
dotnet add package Newtonsoft.Json
46
-
```
45
+
```dotnetcli
46
+
dotnet package add Newtonsoft.Json
47
+
```
47
48
48
-
2. After the command finishes, open the *Nuget.Quickstart.csproj* file in Visual Studio to see the added NuGet package reference:
49
+
If you're using .NET 9 or earlier, use the verb-first form instead:
In code, you refer to installed packages by using a `using <namespace>` directive, where `<namespace>` is often the package name. You can then use the package's API in your project.
66
+
58
67
1. In Visual Studio, open the *Program.cs* file and add the following line at the top of the file:
59
68
60
-
```cs
61
-
using Newtonsoft.Json;
62
-
```
69
+
```cs
70
+
usingNewtonsoft.Json;
71
+
```
63
72
64
73
1. Add the following code to replace the `Console.WriteLine("Hello, World!");` statement:
1. Save the file, and then build and run the app by using the `dotnet run` command. The output is the JSON representation of the `Account` object in the code:
Find more NuGet videos on [Channel 9](/shows/NuGet-101/) and [YouTube](https://www.youtube.com/playlist?list=PLdo4fOcmZ0oVLvfkFk8O9h6v2Dcdh2bh_).
108
-
109
-
## Next steps
116
+
For videos about using NuGet for package management, see [.NET Package Management with NuGet for Beginners](/shows/dotnet-package-management-with-nuget-for-beginners/) and [NuGet for Beginners](https://www.youtube.com/playlist?list=PLdo4fOcmZ0oVLvfkFk8O9h6v2Dcdh2bh_).
110
117
111
-
Learn more about installing and using NuGet packages with the dotnet CLI:
118
+
## Related content
112
119
113
-
> [!div class="nextstepaction"]
114
-
> [Install and use packages by using the dotnet CLI](../consume-packages/install-use-packages-dotnet-cli.md)
120
+
To find out more about installing and using NuGet packages by using the dotnet CLI, see the following articles:
115
121
116
-
- [Overview and workflow of package consumption](../consume-packages/overview-and-workflow.md)
117
-
- [Find and choose packages](../consume-packages/finding-and-choosing-packages.md)
118
-
- [Package references in project files](../consume-packages/package-references-in-project-files.md)
122
+
-[Install and manage NuGet packages with the dotnet CLI](../consume-packages/install-use-packages-dotnet-cli.md)
0 commit comments