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?
From the command line or the terminal windows in VS Code editor:
dotnet add <PROJECT> package <PACKAGE_NAME> [options]
Ex.:
dotnet add MyApp package MySql.Data -Version 8.0.31
See this article by Scott Hanselman
--version
or -v
( not -Version
); (2) I had to include the .csproj
file extension. Full example that worked for me: dotnet add MyApp.csproj package MySql.Data --version 8.0.31
–
Jamille 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:
Type a part of your package's name as search string:
Choose the package:
And finally the package version (you probably want the newest one):
You can do it easily using "vscode-nuget-package-manager".
Go to the marketplace and install this. After That:
- Press Ctrl+P or Ctrl+Shift+P (and skip 2)
- Type ">"
- Then select "Nuget Package Manager:Add Package"
- Enter package name Ex: Dapper
- select package name and version
- Done.
Nuget Gallery
provides a GUI similar to the full Visual Studio. See below.
How To Use:
- Install
Nuget Gallery
from extension marketplace. - Launch from the menu bar
View > Command Palette
or ⇧⌘P (Ctrl+Shift+P on Windows and Linux). TypeNuget: Open Gallery
. - The GUI above is displayed. You can filter just like in regular Visual Studio.
- 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.
.csproj
file tick option in the current version. Maybe that's what my problem is. github.com/pcislo/vscode-nuget-gallery/issues/15 –
Gagliano .csproj
not having version numbers. See issue comment. I've updated my answer to include that. –
Brecciate Open extensions menu (Ctrl+Shift+X), and search ".NuGet Package Manager".
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.
dotnet
and VSCode then why would you even need those project files. –
Bump 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:
- Open your project workspace in VSCode
- Open the Command Palette (Ctrl+Shift+P)
- Select > Nuget Package Manager GUI
- Click Install New Package
For update/remove the packages click Update/Remove Packages
If you're working with .net core, you can use the dotnet CLI, for instance
dotnet add package <package name>
- Install NuGet Package Manager
Ctrl+Shift+P
on Windows orCommand+Shift+P
on Mac- Search for NuGet Package Manager: Add Package
- Enter package name i.e. AutoMapper
- Select package & version
- Restore if needed
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
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"
}
}
Go to folder that have a sln file. Open a terminal (like cmd)
dotnet add package <package name>
You can use .NET Add Command
Usage: dotnet add [PROJECT] [command] [options]
Arguments: PROJECT: The project file to operate on. If a file is not specified, the command will search the current directory for one.
Options: -?, -h, --help Show command line help.
Commands:
package <PACKAGE_NAME> Add a NuGet package reference to the project.
reference <PROJECT_PATH> Add a project-to-project reference to the project.
© 2022 - 2024 — McMap. All rights reserved.