How to install .NET Core Nuget packages using VS Code?

7

I'm using VS Code to develop a .NET Core project and would like to know how to install packages in Nuget on it.

In Visual Studio, there is a specific terminal for this, the Package Manager Console . You need to use the Add-Package command to install something.

For example, to install the Entity Framework you can use this command

PM> Add-Package EntityFramework

How can I install a package using Visual Studio Code?

    
asked by anonymous 27.11.2017 / 19:46

2 answers

7

Using the dotnet add command of the .NET Core CLI

You can do this using the .NET Core CLI with the command dotnet add , the package option, and the package name shortly thereafter.

For example, to add the latest version of the Entity Framework.

MeuProjeto> dotnet add package EntityFramework

To specify a version, you can use the --version argument.

MeuProjeto> dotnet add package EntityFramework --version=6.0

To specify the project where dependency is to be added, you must use the project's csproj file path shortly after add .

For example, to add the Entity Framework to the project ProjetoModels

MeuProjeto> dotnet add ProjetoModels.csproj package EntityFramework

This will check if the package version is compatible with the project and, if it is compatible, will add the dependency in the project files and also download it using the dotnet restore / p>

  

Tip : To open a terminal within the VS Code, in the project folder use the key combination Ctrl + strong> '

Add the dependency manually in XML

You can also manually add the reference to the project file. To do this, just open the .csproj file, search for the ItemGroup section and add a PackageReference

For example, to add the Entity Framework version 6.2.0 .

<ItemGroup>
  <PackageReference Include="EntityFramework" Version="6.2.0" />
</ItemGroup>

After that, you have to run the dotnet restore command to get the files downloaded.

27.11.2017 / 19:46
2

Another option would be to use the

  

jmrog.vscode-nuget-package-manager

It allows you to add packages graphically, after installing the extension and restarting vscode, you need to:

  • Open the "Command Palette" normally using Ctrl + shift + p, search for "Nuget Package Manager" and enter the name of the package you want to install, this is useful when the package name is not known exactly as it will be displayed a list with all the results that match the search.
  • Click the desired package
  • Choose version
  • Choose which project to install
  • You will see an option suggesting that you perform the restore in the project in which the package was added, or perform dotnet restore manually
  • It is very useful when you are not sure about the full name of the package, or for people who prefer to work graphically.

        
    08.02.2018 / 12:37