How to install a NuGet package in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
6 min

banner

# Table of Contents

  1. How to install a NuGet package in Visual Studio Code
  2. Using NuGet Package Manager GUI to install a NuGet package in Visual Studio Code
  3. Using the NuGet Gallery Extension to install packages in VS Code
  4. Using a different extension to install a NuGet package in VS Code

# How to install a NuGet package in Visual Studio Code

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.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
  1. Type toggle terminal and select View: Toggle Terminal.

vscode open terminal

You can also open the terminal by using the keyboard shortcut:

  • on Windows and Linux: press Ctrl + ` (backtick).
  • on macOS: press Ctrl + ` (backtick).
  1. Use the following command to install a NuGet package.
shell
dotnet add package <PACKAGE_NAME>

For example, here's a command that installs the System.Net.Http package.

shell
dotnet add package System.Net.Http

install nuget package using terminal

You can also install a specific version by using the --version flag.

shell
dotnet add package System.Net.Http --version 4.3.4

install specific version of nuget package using terminal

You can also specify the project when issuing the dotnet add command.

shell
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.

shell
dotnet add MyApp package System.Net.Http

You can use the nuget.org website if you need to search for .NET packages.

search for dot net packages

When you click on a specific package, make sure the .NET CLI tab is selected and copy the command.

copy nuget package installation command

Paste the command in your VS Code integrated terminal to install the NuGet package.

# Using NuGet Package Manager GUI to install a NuGet package in Visual Studio Code

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.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type NuGet Package Manager GUI.

install nuget package manager gui extension

  1. Select the extension and click on the Install button.

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:

  1. Press:
  • Ctrl + P on Windows and Linux.
  • Command + P on macOS.
  1. Type the following command and press Enter.
shell
ext install aliasadidev.nugetpackagemanagergui

install nuget package manager gui extension using command palette

Once you install the extension:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type NuGet package and select NuGet Package Manager GUI.

start nuget package manager gui

  1. Click on the Install New Package button in the top bar.

Note: If you need to update or remove packages, click on the Update / Remove Packages button.

  1. Start typing the name of the package and press 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.

  1. Once you find the package you want to install, click on the Install button.

You can also optionally select a version from the dropdown menu.

click install button to install nuget package

  1. If you need to update or remove a package, click on the Update / Remove Packages button at the top.

click update remove package

  1. Start typing the name of the package and press Enter.

  2. Click on the Update or Update All buttons for the specific package if you need to update the package.

  3. If you need to remove the package, click on Remove or Remove All.

update or remove nuget package

# Using the NuGet Gallery Extension to install packages in VS Code

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.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type NuGet Gallery.

install nuget gallery extension

  1. Select the extension and click on the Install button.

You can also install the extension using a command.

  1. Press:
  • Ctrl + P on Windows and Linux.
  • Command + P on macOS.
  1. Type the following command and press Enter.
shell
ext install patcx.vscode-nuget-gallery

Once you install the extension:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type NuGet open and select NuGet: Open NuGet Gallery.

nuget open nuget gallery

  1. Type the name of the package in the Search field and press Enter.

filter for nuget packages

  1. Left-click on the package you'd like to install.

check checkbox and click install

  1. Check the checkbox for the .csproj file as shown in the screenshot.
  2. Select the version of the package you'd like to install from the dropdown menu.
  3. Click on the Install button.

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.

# Using a different extension to install a NuGet package in VS Code

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.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type NuGet Package Manager.

install nuget package manager extension

  1. Select the extension and click on the Install button.

Make sure to install the correct NuGet Package Manager extension from the user jmrog.

You can also install the extension using a command.

  1. Press:
  • Ctrl + P on Windows and Linux.
  • Command + P on macOS.
  1. Type the following command and press Enter.
shell
ext install jmrog.vscode-nuget-package-manager

Once you install the extension:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type NuGet package manager.

type nuget package manager

  1. Click on NuGet Package Manager: Add Package.

  2. Start typing the name of the package and press Enter.

  3. The command will pull packages with similar names from the repository.

select correct package from list

  1. Use the arrow keys to select the correct package and press Enter.

  2. Select the version of the package to be installed and hit Enter.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.