Last updated: Apr 6, 2024
Reading time·6 min
There are multiple ways to install a NuGet package in VS Code. You can use the integrated terminal or an extension package manager.
This article covers both approaches and shows how to use the 3 most popular NuGet package manager extensions in VS Code.
The easiest way to install a NuGet package in Visual Studio Code is to use the integrated terminal.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.You can also open the terminal by using the keyboard shortcut:
Ctrl
+ ` (backtick).Ctrl
+ ` (backtick).dotnet add package <PACKAGE_NAME>
For example, here's a command that installs the System.Net.Http
package.
dotnet add package System.Net.Http
You can also install a specific version by using the --version
flag.
dotnet add package System.Net.Http --version 4.3.4
You can also specify the project when issuing the dotnet add
command.
dotnet add <PROJECT_NAME> package <PACKAGE_NAME>
For example, assuming your project's name is MyApp and you want to install the
System.Net.Http
package.
dotnet add MyApp package System.Net.Http
You can use the nuget.org website if you need to search for .NET packages.
When you click on a specific package, make sure the .NET CLI tab is selected and copy the command.
Paste the command in your VS Code integrated terminal to install the NuGet package.
Alternatively, you can use the NuGet Package Manager GUI extension.
The extension is quite popular and easy to use. It enables you to install, update or remove NuGet packages directly in VS Code.
Ctrl
+ Shift
+ X
on Windows or Linux.Command
+ Shift
+ X
on macOS.Make sure to install the correct NuGet Package Manager GUI extension as shown in the screenshot.
You can also use the Quick Open functionality to install the extension:
Ctrl
+ P
on Windows and Linux.Command
+ P
on macOS.Enter
.ext install aliasadidev.nugetpackagemanagergui
Once you install the extension:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Note: If you need to update or remove packages, click on the Update / Remove Packages button.
Enter
or click on the
Search button.If you can't find any packages with the given name, you probably forgot to click on the Install New package button at the top.
You can also optionally select a version from the dropdown menu.
Start typing the name of the package and press Enter
.
Click on the Update or Update All buttons for the specific package if you need to update the package.
If you need to remove the package, click on Remove or Remove All.
If you didn't like the previous extension, you can also try the NuGet Gallery extension which also enables you to install NuGet packages in VS Code.
Ctrl
+ Shift
+ X
on Windows or Linux.Command
+ Shift
+ X
on macOS.You can also install the extension using a command.
Ctrl
+ P
on Windows and Linux.Command
+ P
on macOS.Enter
.ext install patcx.vscode-nuget-gallery
Once you install the extension:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Enter
..csproj
file as shown in the screenshot.The extension will run the installation command directly in your VS Code integrated terminal.
If you need to uninstall a NuGet package, click on the Uninstall button.
If you need to update a package or install an older version, select the version from the dropdown menu and click Install.
There is also a NuGet Package Manager extension that enables you to install NuGet packages in VS Code.
However, using the extension is not recommended because it is not well maintained.
Ctrl
+ Shift
+ X
on Windows or Linux.Command
+ Shift
+ X
on macOS.Make sure to install the correct
NuGet Package Manager
extension from the user jmrog
.
You can also install the extension using a command.
Ctrl
+ P
on Windows and Linux.Command
+ P
on macOS.Enter
.ext install jmrog.vscode-nuget-package-manager
Once you install the extension:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Click on NuGet Package Manager: Add Package.
Start typing the name of the package and press Enter
.
The command will pull packages with similar names from the repository.
Use the arrow keys to select the correct package and press Enter
.
Select the version of the package to be installed and hit Enter
.
You can learn more about the related topics by checking out the following tutorials: