Install a Nuget package in Visual Studio Code

Visual Studio-CodeNuget Package

Visual Studio-Code Problem Overview


How can I install a Nuget Package in Visual Studio Code? I know in Visual Studio, we can do this through the Nuget Package Manager console, but how do I do it in VS Code?

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

From the command line or the Terminal windows in vs code editor dotnet add package Newtonsoft.Json

See this article by Scott Hanselman

Solution 2 - Visual Studio-Code

Edit: From the comments below:

> 22 June 2019: "This extension is now unpublished from Marketplace. You can choose to uninstall it." 2¢. – ruffin Jun 22 '19 at 13:23

> The provided link above points to ".Net Core Project Manager (Nuget)" - try: marketplace.visualstudio.com/… – samis Oct 3 '19 at 16:14


You can use the NuGet Package Manager extension.

After you've installed it, to add a package, press Ctrl+Shift+P, and type >nuget and press Enter:

enter image description here

Type a part of your package's name as search string:

enter image description here

Choose the package:

enter image description here

And finally the package version (you probably want the newest one):

enter image description here

Solution 3 - Visual Studio-Code

You can do it easily using "vscode-nuget-package-manager". Go to the marketplace and install this. After That

  1. Press Ctrl+P or Ctrl+Shift+P (and skip 2)

  2. Type ">"

  3. Then select "Nuget Package Manager:Add Package"

  4. Enter package name Ex: Dapper

  5. select package name and version

  6. Done.

Solution 4 - Visual Studio-Code

Nuget Gallery provides a GUI similar to the full Visual Studio. See below.

enter image description here

How To Use:

  1. Install Nuget Gallery from extension marketplace.
  2. Launch from the menu bar View > Command Palette or ⇧⌘P (Ctrl+Shift+P on Windows and Linux). Type Nuget: Open Gallery.
  3. The GUI above is displayed. You can filter just like in regular Visual Studio.
  4. Make sure the .csproj file checkbox is selected, select version from dropdown, and click install button.

UPDATE

Earlier versions, as noted in the comments, had an issue where the .csproj checkbox was not visible when a package in the csproj file was missing a version number like below.

<PackageReference Include="Microsoft.AspNetCore.App" />

This has been fixed in newer versions of the extension so if you have an older version with this issue, please update it to the latest version.

Solution 5 - Visual Studio-Code

Open extensions menu (Ctrl+Shift+X), and search .NuGet Package Manager.

Solution 6 - Visual Studio-Code

Example for .csproj file

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="7.0.7-m61" />
  </ItemGroup>

Just get package name and version number from NuGet and add to .csproj then save. You will be prompted to run restore that will import new packages.

Solution 7 - Visual Studio-Code

nuget package manager gui extension is a GUI tool that lets you easily update/remove/install packages from Nuget server for .NET Core/.Net 5 projects

> To install new package:

  1. Open your project workspace in VSCode
  2. Open the Command Palette (Ctrl+Shift+P)
  3. Select > Nuget Package Manager GUI
  4. Click Install New Package

Nuget Package Manager GUI

For update/remove the packages click Update/Remove Packages

Nuget Package Manager GUI

Solution 8 - Visual Studio-Code

  1. Install NuGet Package Manager
  2. Ctrl+Shift+P on Windows or Command+Shift+P on Mac
  3. Search for NuGet Package Manager: Add Package
  4. Enter package name i.e. AutoMapper
  5. Select package & version
  6. Restore if needed

Solution 9 - Visual Studio-Code

If you're working with .net core, you can use the dotnet CLI, for instance

dotnet add package <package name>

Solution 10 - Visual Studio-Code

Modify your project.json or *.csproj file. Add a dependency entry with the name of the package and the version desired.

JSON example:

{
   "dependencies" : {

     "AutoMapper": "5.2.0"
   }
}

Solution 11 - Visual Studio-Code

The answers above are good, but insufficient if you have more than 1 project (.csproj) in the same folder.

First, you easily add the "PackageReference" tag to the .csproj file (either manually, by using the nuget package manager or by using the dotnet add package command).

But then, you need to run the "restore" command manually so you can tell it which project you are trying to restore (if I just clicked the restore button that popped up, nothing happened). You can do that by running:

dotnet restore Project-File-Name.csproj

And that installs the package

Solution 12 - Visual Studio-Code

Go to folder that have a sln file. Open a terminal (like cmd)

dotnet add package <package name>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGyan ParkashView Question on Stackoverflow
Solution 1 - Visual Studio-CodeJeff AlbrechtView Answer on Stackoverflow
Solution 2 - Visual Studio-CodesashoalmView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeRoshan PereraView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeMoses MachuaView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeEugeniu ZnagovanView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeChris CavellView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeAli.AsadiView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeRyan EfendyView Answer on Stackoverflow
Solution 9 - Visual Studio-Codeavi siboniView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeMauricio AvilesView Answer on Stackoverflow
Solution 11 - Visual Studio-CodegoolView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeFelipe AugustoView Answer on Stackoverflow