Skip to content

Commit 456b33f

Browse files
authored
Freshness Edit: NuGet (#3555)
* Refresh article and screenshots * Make nuget.org a link; remove Windows from product name * Address Copilot comment: fix typo in alt text
1 parent f32ab34 commit 456b33f

5 files changed

Lines changed: 85 additions & 85 deletions
Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,152 @@
11
---
2-
title: "Quickstart: Install and use a NuGet package in Visual Studio (Windows only)"
3-
description: In this quickstart, you learn how to install and use a NuGet package in a Visual Studio project for Windows.
2+
title: "Quickstart: Install and Use a NuGet Package in Visual Studio (Windows Only)"
3+
description: In this quickstart, find out how to install and use the Newtonsoft.Json NuGet package in a Visual Studio project for Windows.
44
author: JonDouglas
55
ms.author: jodou
6-
ms.date: 03/03/2025
6+
ms.date: 04/16/2026
77
ms.topic: quickstart
8+
# customer intent: As a developer, I want to find out how to install and use a NuGet package in a Visual Studio project so that I can take advantage of available code.
89
---
910

1011
# Quickstart: Install and use a NuGet package in Visual Studio (Windows only)
1112

12-
A *NuGet package* contains reusable code that other developers have made available to you for use in your projects. You can install a NuGet package in a Microsoft Visual Studio project by using the [NuGet Package Manager](../consume-packages/install-use-packages-visual-studio.md), the [Package Manager Console](../consume-packages/install-use-packages-powershell.md), or the [.NET CLI](install-and-use-a-package-using-the-dotnet-cli.md). This article demonstrates how to create a Windows Presentation Foundation (WPF) project with the popular `Newtonsoft.Json` package. The same process applies to any other .NET or .NET Core project.
13+
In this quickstart, you use Microsoft Visual Studio to install and use a *NuGet package* in a project. A NuGet package contains reusable code that other developers make available to you for use in your projects.
1314

14-
After you install a NuGet package, you can then make a reference to it in your code with the `using <namespace>` statement, where \<namespace\> is the name of package you're using. After you've made a reference, you can then call the package through its API.
15+
You can install a NuGet package in a Visual Studio project by using the [NuGet Package Manager](../consume-packages/install-use-packages-visual-studio.md), the [Package Manager Console](../consume-packages/install-use-packages-powershell.md), or the [.NET command-line interface (CLI)](install-and-use-a-package-using-the-dotnet-cli.md). This quickstart demonstrates how to use the NuGet Package Manager and the Package Manager Console to install a package. You follow steps for creating a Windows Presentation Foundation (WPF) project that uses the popular `Newtonsoft.Json` package. The same process applies to any other .NET project.
1516

16-
The article is for Windows users only. If you're using Visual Studio for Mac, see [Install and use a package in Visual Studio for Mac](install-and-use-a-package-in-visual-studio-mac.md).
17+
This article is for Windows users only. If you're using Visual Studio for Mac, see [Install and use a package in Visual Studio for Mac](install-and-use-a-package-in-visual-studio-mac.md).
1718

1819
> [!TIP]
19-
> To find a NuGet package, start with *nuget.org*. Browsing nuget.org is how .NET developers typically find components they can reuse in their own applications. You can do a search of nuget.org directly or find and install packages within Visual Studio as shown in this article. For more information, see [Find and evaluate NuGet packages](../consume-packages/finding-and-choosing-packages.md).
20+
> To find a NuGet package, start with [nuget.org](https://www.nuget.org/). Browsing nuget.org is how .NET developers typically find components they can reuse in their own applications. You can do a search of nuget.org directly or find and install packages within Visual Studio as shown in this article. For more information, see [Find and evaluate NuGet packages for your project](../consume-packages/Finding-and-Choosing-Packages.md).
2021
2122
## Prerequisites
2223

23-
- Install Visual Studio 2022 for Windows with the .NET desktop development workload.
24+
- Install Visual Studio 2026 with the .NET desktop development workload.
2425

25-
You can install the 2022 Community edition for free from [visualstudio.microsoft.com](https://visualstudio.microsoft.com/), or use the Professional or Enterprise edition.
26+
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.
2627

2728
## Create a project
2829

29-
You can install a NuGet package into any .NET project if that package supports the same target framework as the project. However, for this quickstart you'll create a Windows Presentation Foundation (WPF) Application project.
30+
You can install a NuGet package into any .NET project if that package supports the same target framework as the project. For this quickstart, you create a WPF Application project.
3031

3132
Follow these steps:
3233

33-
1. In Visual Studio, select **File** > **New** > **Project**.
34+
1. In Visual Studio, select **File** > **New** > **Project/Solution**.
3435

35-
1. In the **Create a new project** window, enter *WPF* in the search box and select **C#** and **Windows** in the dropdown lists. In the resulting list of project templates, select **WPF Application**, and then select **Next**.
36+
1. In the **Create a new project** window, go to the search box and enter **wpf**. In the resulting list of project templates, select the **WPF Application** template that has **C#** and **Windows** tags, and then select **Next**.
3637

37-
1. In the **Configure your new project** window, optionally update the **Project name** and the **Solution name**, and then select **Next**.
38+
1. In the **Configure your new project** window, optionally update the **Project name** and **Solution name** values, and then select **Next**.
3839

39-
1. In the **Additional information** window, select **.NET 6.0** (or the latest version) for **Framework**, and then select **Create**.
40+
1. In the **Additional information** window, under **Framework**, select **.NET 10.0** (or the latest version), and then select **Create**.
4041

4142
Visual Studio creates the project, and it appears in [Solution Explorer](/visualstudio/ide/use-solution-explorer).
4243

4344
## Add the Newtonsoft.Json NuGet package
4445

45-
To install a NuGet package in this quickstart, you can use either the NuGet Package Manager or the Package Manager Console. Depending on your project format, the installation of a NuGet package records the dependency in either your project file or a *packages.config* file. For more information, see [Package consumption workflow](../consume-packages/overview-and-workflow.md).
46+
To install a NuGet package in this quickstart, you can use either the NuGet Package Manager or the Package Manager Console. Depending on your project format, the installation of a NuGet package records the dependency in either your project file or a *packages.config* file. For more information, see [Package consumption workflow](../consume-packages/Overview-and-Workflow.md).
4647

4748
### NuGet Package Manager
4849

4950
To use the [NuGet Package Manager](../consume-packages/install-use-packages-visual-studio.md) to install the `Newtonsoft.Json` package in Visual Studio, follow these steps:
5051

5152
1. Select **Project** > **Manage NuGet Packages**.
5253

53-
1. In the **NuGet Package Manager** page, choose **nuget.org** as the **Package source**.
54+
1. On the **NuGet Package Manager** page, next to **Package source**, select **nuget.org**.
5455

55-
1. From the **Browse** tab, search for *Newtonsoft.Json*, select **Newtonsoft.Json** in the list, and then select **Install**.
56+
1. Go to the **Browse** tab and search for **Newtonsoft.Json**. In the list, select **Newtonsoft.Json**, and then select **Install**.
5657

57-
:::image type="content" source="media/qs-use-install-package.png" alt-text="Screenshot showing the NuGet Package Manager window with the Newtonsoft.Json package selected.":::
58+
:::image type="content" source="media/qs-use-install-package.png" alt-text="Screenshot of the NuGet Package Manager. The Newtonsoft.Json package is selected. Its details pane displays package data and has an Install button." lightbox="media/qs-use-install-package.png":::
5859

59-
1. If you're prompted to verify the installation, select **OK**.
60+
1. If you're prompted to verify the installation, select **Apply**.
6061

6162
### Package Manager Console
6263

6364
Alternatively, to use the [Package Manager Console](../consume-packages/install-use-packages-powershell.md) in Visual Studio to install the `Newtonsoft.Json` package, follow these steps:
6465

65-
1. From Visual Studio, select **Tools** > **NuGet Package Manager** > **Package Manager Console**.
66+
1. In Visual Studio, select **Tools** > **NuGet Package Manager** > **Package Manager Console**.
6667

67-
1. After the **Package Manager Console** pane opens, verify that the **Default project** drop-down list shows the project in which you want to install the package. If you have a single project in the solution, it's preselected.
68+
1. At the top of the **Package Manager Console** window, verify that the **Default project** list shows the project in which you want to install the package. If you have a single project in the solution, it's preselected.
6869

69-
:::image type="content" source="media/qs-use-package-manager-console.png" alt-text="Screenshot showing the Package Manage Console window with Default project highlighted.":::
70+
:::image type="content" source="media/qs-use-package-manager-console.png" alt-text="Screenshot of the Package Manager Console window, which contains information about the version and licensing. The Default project list is highlighted." lightbox="media/qs-use-package-manager-console.png":::
7071

7172
1. At the console prompt, enter the command `Install-Package Newtonsoft.Json`. For more information about this command, see [Install-Package](../reference/ps-reference/ps-ref-install-package.md).
7273

7374
The console window shows the output for the command. Errors typically indicate that the package isn't compatible with the project's target framework.
7475

7576
## Use the Newtonsoft.Json API in the app
7677

77-
With the `Newtonsoft.Json` package in the project, call its `JsonConvert.SerializeObject` method to convert an object to a human-readable string:
78-
79-
1. From **Solution Explorer**, open *MainWindow.xaml* and replace the existing `<Grid>` element with the following code:
80-
81-
```xaml
82-
<Grid Background="White">
83-
<StackPanel VerticalAlignment="Center">
84-
<Button Click="Button_Click" Width="100px" HorizontalAlignment="Center" Content="Click Me" Margin="10"/>
85-
<TextBlock Name="TextBlock" HorizontalAlignment="Center" Text="TextBlock" Margin="10"/>
86-
</StackPanel>
87-
</Grid>
88-
```
89-
90-
1. Open the *MainWindow.xaml.cs* file under the *MainWindow.xaml* node, and insert the following code inside the `MainWindow` class after the constructor:
91-
92-
```csharp
93-
public class Account
94-
{
95-
public string Name { get; set; }
96-
public string Email { get; set; }
97-
public DateTime DOB { get; set; }
98-
}
99-
100-
private void Button_Click(object sender, RoutedEventArgs e)
101-
{
102-
Account account = new Account
103-
{
104-
Name = "John Doe",
105-
Email = "[email protected]",
106-
DOB = new DateTime(1980, 2, 20, 0, 0, 0, DateTimeKind.Utc),
107-
};
108-
string json = JsonConvert.SerializeObject(account, Newtonsoft.Json.Formatting.Indented);
109-
TextBlock.Text = json;
110-
}
111-
```
112-
113-
1. To avoid an error for the `JsonConvert` object in the code (a red squiggle line will appear), add the following statement at the beginning of the code file:
114-
115-
```csharp
116-
using Newtonsoft.Json;
117-
```
118-
119-
1. To build and run the app, press F5 or select **Debug** > **Start Debugging**.
78+
After you install a NuGet package, you can make a reference to it in your code by using the `using <namespace>` statement, where \<namespace\> is the name of the package you're using. After you make a reference, you can call the package through its API.
12079

121-
The following window appears:
80+
With the `Newtonsoft.Json` package in the project, you can call its `JsonConvert.SerializeObject` method. To use this method to convert an object to a human-readable string, take these steps:
12281

123-
![Screenshot showing the initial output of the WPF app.](media/qs-use-wpf-app-start.png)
82+
1. In **Solution Explorer**, open *MainWindow.xaml* and replace the existing `<Grid>` element with the following code:
12483

125-
1. Select the **Click Me** button to see the contents of the `TextBlock` object replaced with JSON text.
84+
```xaml
85+
<Grid Background="White">
86+
<StackPanel VerticalAlignment="Center">
87+
<Button Click="Button_Click" Width="100px" HorizontalAlignment="Center" Content="Click Me" Margin="10"/>
88+
<TextBlock Name="TextBlock" HorizontalAlignment="Center" Text="TextBlock" Margin="10"/>
89+
</StackPanel>
90+
</Grid>
91+
```
12692

127-
![Screenshot showing the output of the WPF app after selecting the button.](media/qs-use-wpf-app-end.png)
93+
1. In **Solution Explorer**, expand the **MainWindow.xaml** node, and then open the *MainWindow.xaml.cs* file. Insert the following code inside the `MainWindow` class, after the constructor:
12894

129-
## Related video
95+
```csharp
96+
public class Account
97+
{
98+
public string ID { get; set; }
99+
public decimal Balance { get; set; }
100+
public DateTime Created { get; set; }
101+
}
130102

131-
- Find NuGet videos on [Channel 9](/shows/nuget-101/) and [YouTube](https://www.youtube.com/playlist?list=PLdo4fOcmZ0oVLvfkFk8O9h6v2Dcdh2bh_).
103+
private void Button_Click(object sender, RoutedEventArgs e)
104+
{
105+
Account account = new Account
106+
{
107+
ID = "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u",
108+
Balance = 4389.21m,
109+
Created = new DateTime(2026, 4, 16, 0, 0, 0, DateTimeKind.Utc),
110+
};
111+
string json = JsonConvert.SerializeObject(account, Newtonsoft.Json.Formatting.Indented);
112+
TextBlock.Text = json;
113+
}
114+
```
132115

133-
## See also
116+
1. If *MainWindow.xaml.cs* doesn't contain the following line, add it to the beginning of the file:
134117

135-
For more information about NuGet, see the following articles:
118+
```csharp
119+
using Newtonsoft.Json;
120+
```
136121

137-
- [What is NuGet?](../what-is-nuget.md)
138-
- [Package consumption workflow](../consume-packages/overview-and-workflow.md)
139-
- [Find and choose packages](../consume-packages/finding-and-choosing-packages.md)
140-
- [Package references in project files](../consume-packages/package-references-in-project-files.md)
141-
- [Install and use a package using the .NET CLI](install-and-use-a-package-using-the-dotnet-cli.md).
142-
- [Newtonsoft.Json package](https://www.nuget.org/packages/newtonsoft.json)
122+
Without this line, Visual Studio marks the `JsonConvert` object with a red, squiggly line to indicate an error.
123+
124+
1. To build and run the app, select **F5**, or select **Debug** > **Start Debugging**.
125+
126+
The following window appears:
127+
128+
:::image type="content" source="media/qs-use-wpf-app-start.png" alt-text="Screenshot of the MainWindow window that the app creates in Visual Studio. The window contains a Click Me button and the term TextBlock." lightbox="media/qs-use-wpf-app-start.png":::
143129

144-
## Next steps
130+
1. Select **Click Me**. The app updates the window by replacing the `TextBlock` object with JSON text.
145131

146-
Congratulations on installing and using your first NuGet package. Advance to the next article to learn more about installing and managing NuGet packages.
132+
:::image type="content" source="media/qs-use-wpf-app-end.png" alt-text="Screenshot of the MainWindow window in Visual Studio, which contains a Click Me button and JSON code that lists ID, Balance, and Created values." lightbox="media/qs-use-wpf-app-end.png":::
147133

148-
> [!div class="nextstepaction"]
149-
> [Install and manage packages using using the NuGet Package Manager](../consume-packages/install-use-packages-visual-studio.md)
134+
## Related videos
150135

151-
> [!div class="nextstepaction"]
152-
> [Install and manage packages using the Package Manager Console](../consume-packages/install-use-packages-powershell.md)
136+
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_).
137+
138+
## Related content
139+
140+
To find out more about installing and managing NuGet packages, see the following articles:
141+
142+
- [Install and manage packages in Visual Studio using the NuGet Package Manager](../consume-packages/install-use-packages-visual-studio.md)
143+
- [Manage packages with the Visual Studio Package Manager Console (PowerShell)](../consume-packages/install-use-packages-powershell.md)
144+
145+
For more information about NuGet, see the following articles:
146+
147+
- [An introduction to NuGet](../what-is-nuget.md)
148+
- [Package consumption workflow](../consume-packages/Overview-and-Workflow.md)
149+
- [Find and evaluate NuGet packages for your project](../consume-packages/Finding-and-Choosing-Packages.md)
150+
- [`PackageReference` in project files](../consume-packages/Package-References-in-Project-Files.md)
151+
- [Install and use a package with the dotnet CLI](install-and-use-a-package-using-the-dotnet-cli.md)
152+
- [Newtonsoft.Json package](https://www.nuget.org/packages/newtonsoft.json)
18.3 KB
Loading
-9.89 KB
Loading
-8.3 KB
Loading
-6.79 KB
Loading

0 commit comments

Comments
 (0)