Skip to content

Commit ec32ca0

Browse files
committed
Refresh article
1 parent cc4ba54 commit ec32ca0

1 file changed

Lines changed: 73 additions & 66 deletions

File tree

Lines changed: 73 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
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-
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).
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 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).
1819
1920
## Prerequisites
2021

2122
- 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 dotnet CLI. In Visual Studio, the dotnet CLI automatically installs with any .NET-related workloads.
2324

2425
## Create a project
2526

@@ -31,88 +32,94 @@ You can install NuGet packages into a .NET project. For this quickstart, take th
3132

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

34-
```dotnetcli
35-
dotnet new console
36-
```
35+
```dotnetcli
36+
dotnet new console
37+
```
3738

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!`.
3940

4041
## Add the Newtonsoft.Json NuGet package
4142

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

44-
```dotnetcli
45-
dotnet add package Newtonsoft.Json
46-
```
45+
```dotnetcli
46+
dotnet package add Newtonsoft.Json
47+
```
4748

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:
4950

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

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

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

60-
```cs
61-
using Newtonsoft.Json;
62-
```
69+
```cs
70+
using Newtonsoft.Json;
71+
```
6372

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

66-
```cs
67-
namespace Nuget.Quickstart
68-
{
69-
public class Account
70-
{
71-
public string? Name { get; set; }
72-
public string? Email { get; set; }
73-
public DateTime DOB { get; set; }
74-
}
75-
internal class Program
76-
{
77-
static void Main(string[] args)
78-
{
79-
Account account = new Account
80-
{
81-
Name = "John Doe",
82-
Email = "[email protected]",
83-
DOB = new DateTime(1980, 2, 20, 0, 0, 0, DateTimeKind.Utc),
84-
};
85-
86-
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
87-
Console.WriteLine(json);
88-
}
89-
}
90-
}
91-
```
75+
```cs
76+
namespace Nuget.Quickstart
77+
{
78+
public class Account
79+
{
80+
public string? ID { get; set; }
81+
public decimal Balance { get; set; }
82+
public DateTime Created { get; set; }
83+
}
84+
internal class Program
85+
{
86+
static void Main(string[] args)
87+
{
88+
Account account = new Account
89+
{
90+
ID = "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u",
91+
Balance = 4389.21m,
92+
Created = new DateTime(2026, 4, 16, 0, 0, 0, DateTimeKind.Utc),
93+
};
94+
95+
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
96+
Console.WriteLine(json);
97+
}
98+
}
99+
}
100+
```
92101

93102
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:
94103

95-
```output
96-
{
97-
"Name": "John Doe",
98-
"Email": "[email protected]",
99-
"DOB": "1980-02-20T00:00:00Z"
100-
}
101-
```
104+
```output
105+
{
106+
"ID": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u",
107+
"Balance": "4389.21",
108+
"Created": "2026-04-16T00:00:00Z"
109+
}
110+
```
102111

103112
## Related videos
104113

105114
> [!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]
106115
107-
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_).
110117

111-
Learn more about installing and using NuGet packages with the dotnet CLI:
118+
## Related content
112119

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:
115121

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)
123+
- [Package consumption workflow](../consume-packages/Overview-and-Workflow.md)
124+
- [Find and evaluate NuGet packages for your project](../consume-packages/Finding-and-Choosing-Packages.md)
125+
- [`PackageReference` in project files](../consume-packages/Package-References-in-Project-Files.md)

0 commit comments

Comments
 (0)