Skip to content

Commit 513b13b

Browse files
authored
Freshness Edit: NuGet (#3557)
* Refresh article * Refresh article * Address Copilot comments: remove Visual Studio from prerequisites, remove quotes, change variable name, update link
1 parent c6ee297 commit 513b13b

1 file changed

Lines changed: 81 additions & 76 deletions

File tree

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,124 @@
11
---
2-
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.
44
author: JonDouglas
55
ms.author: jodou
6-
ms.date: 03/03/2025
6+
ms.date: 04/17/2026
77
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.
89
---
910

1011
# Quickstart: Install and use a package with the dotnet CLI
1112

12-
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). This quickstart describes how to 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.
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).
1314

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).
1516

1617
> [!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 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/packages](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).
1819
1920
## Prerequisites
2021

21-
- The [.NET 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 any .NET or .NET Core related workloads.
22+
The [.NET SDK](https://dotnet.microsoft.com/download), which provides the dotnet CLI. In Visual Studio, the dotnet CLI automatically installs with any .NET-related workloads.
2223

2324
## Create a project
2425

25-
You can install NuGet packages into a .NET project. For this walkthrough, create a simple .NET console project by using the dotnet CLI, as follows:
26+
You can install NuGet packages into a .NET project. For this quickstart, take the following steps to create a basic .NET console project by using the dotnet CLI:
2627

2728
1. Create a folder named *Nuget.Quickstart* for the project.
2829

29-
1. Open a command prompt and switch to the new folder.
30+
1. Open a command prompt window and go to the new folder.
3031

3132
1. Create the project by using the following command:
3233

33-
```dotnetcli
34-
dotnet new console
35-
```
34+
```dotnetcli
35+
dotnet new console
36+
```
3637

37-
1. Use `dotnet run` to test the app. You should see the output `Hello, World!`.
38+
1. Use `dotnet run` to test the app. The command writes the following output to the screen: `Hello, World!`.
3839

3940
## Add the Newtonsoft.Json NuGet package
4041

41-
1. Use the following command to install the `Newtonsoft.json` package:
42+
1. Use the following command to install the `Newtonsoft.Json` package:
4243

43-
```dotnetcli
44-
dotnet add package Newtonsoft.Json
45-
```
44+
```dotnetcli
45+
dotnet package add Newtonsoft.Json
46+
```
4647

47-
2. After the command completes, open the *Nuget.Quickstart.csproj* file in Visual Studio to see the added NuGet package reference:
48+
If you're using .NET 9 or earlier, use the verb-first form instead:
4849

49-
```xml
50-
<ItemGroup>
51-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
52-
</ItemGroup>
53-
```
50+
```dotnetcli
51+
dotnet add package Newtonsoft.Json
52+
```
53+
54+
1. After the command finishes, open the *Nuget.Quickstart.csproj* file in Visual Studio or in a text editor. Check for the added NuGet package reference:
55+
56+
```xml
57+
<ItemGroup>
58+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
59+
</ItemGroup>
60+
```
5461

5562
## Use the Newtonsoft.Json API in the app
5663

57-
1. In Visual Studio, open the *Program.cs* file and add the following line at the top of the file:
64+
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.
5865

59-
```cs
60-
using Newtonsoft.Json;
61-
```
66+
1. In Visual Studio or in a text editor, open the *Program.cs* file. Add the following line to the top of the file:
67+
68+
```cs
69+
using Newtonsoft.Json;
70+
```
6271

6372
1. Add the following code to replace the `Console.WriteLine("Hello, World!");` statement:
6473

65-
```cs
66-
namespace Nuget.Quickstart
67-
{
68-
public class Account
69-
{
70-
public string? Name { get; set; }
71-
public string? Email { get; set; }
72-
public DateTime DOB { get; set; }
73-
}
74-
internal class Program
75-
{
76-
static void Main(string[] args)
77-
{
78-
Account account = new Account
79-
{
80-
Name = "John Doe",
81-
Email = "[email protected]",
82-
DOB = new DateTime(1980, 2, 20, 0, 0, 0, DateTimeKind.Utc),
83-
};
84-
85-
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
86-
Console.WriteLine(json);
87-
}
88-
}
89-
}
90-
```
91-
92-
1. Save the file, 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:
93-
94-
```output
95-
{
96-
"Name": "John Doe",
97-
"Email": "[email protected]",
98-
"DOB": "1980-02-20T00:00:00Z"
99-
}
100-
```
101-
102-
Congratulations on installing and using your first NuGet package!
103-
104-
## Related video
74+
```cs
75+
namespace Nuget.Quickstart
76+
{
77+
public class Account
78+
{
79+
public string? Id { get; set; }
80+
public decimal Balance { get; set; }
81+
public DateTime Created { get; set; }
82+
}
83+
internal class Program
84+
{
85+
static void Main(string[] args)
86+
{
87+
Account account = new Account
88+
{
89+
Id = "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u",
90+
Balance = 4389.21m,
91+
Created = new DateTime(2026, 4, 16, 0, 0, 0, DateTimeKind.Utc),
92+
};
93+
94+
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
95+
Console.WriteLine(json);
96+
}
97+
}
98+
}
99+
```
100+
101+
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:
102+
103+
```output
104+
{
105+
"Id": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u",
106+
"Balance": 4389.21,
107+
"Created": "2026-04-16T00:00:00Z"
108+
}
109+
```
110+
111+
## Related videos
105112

106113
> [!VIDEO https://learn-video.azurefd.net/vod/player?show=dotnet-package-management-with-nuget-for-beginners&ep=installing-a-nuget-package-using-the-dotnet-cli-nuget-for-beginners]
107114
108-
Find more NuGet videos on [Channel 9](/shows/NuGet-101/) and [YouTube](https://www.youtube.com/playlist?list=PLdo4fOcmZ0oVLvfkFk8O9h6v2Dcdh2bh_).
109-
110-
## Next steps
115+
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_).
111116

112-
Learn more about installing and using NuGet packages with the dotnet CLI:
117+
## Related content
113118

114-
> [!div class="nextstepaction"]
115-
> [Install and use packages by using the dotnet CLI](../consume-packages/install-use-packages-dotnet-cli.md)
119+
To find out more about installing and using NuGet packages by using the dotnet CLI, see the following articles:
116120

117-
- [Overview and workflow of package consumption](../consume-packages/overview-and-workflow.md)
118-
- [Find and choose packages](../consume-packages/finding-and-choosing-packages.md)
119-
- [Package references in project files](../consume-packages/package-references-in-project-files.md)
121+
- [Install and manage NuGet packages with the dotnet CLI](../consume-packages/install-use-packages-dotnet-cli.md)
122+
- [Package consumption workflow](../consume-packages/Overview-and-Workflow.md)
123+
- [Find and evaluate NuGet packages for your project](../consume-packages/Finding-and-Choosing-Packages.md)
124+
- [`PackageReference` in project files](../consume-packages/Package-References-in-Project-Files.md)

0 commit comments

Comments
 (0)