0

I've got a private package stored on a feed in VSTS (Visual Studio Team Services). I want add it on a .NET Core project that I'm developing in Visual Studio Code.

Checking VSTS documentation, to add a package from private source it's necessary use the NuGet CLI, because .NET doesn't have support for private repositories (or at least I suppose it, because Microsoft recommend us to use NuGet CLI instead).

Using NuGet CLI, the command to add a package is NuGet install. But it downloads all packages, with .nupck, DLL files, a large, etc... (i.e., various XML files). And it doesn't add the necessary references to the project. Using .NET CLI to add the package, it adds the references in the .csproj file (project file), and it works as usual.

Is there a command that reproduces exactly the same behaviour like if we add package on Visual Studio, or Visual Code using .NET add package CLI?

If not, what I should do? Should I extract the DLL file and reference it manually in the .csproj file? If there's any update, how can I know it (in Visual Studio the NuGet UI shows me updates, but in Visual Studio Code, after adding a reference manually...)

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
JorgeAM
  • 91
  • 1
  • 7

1 Answers1

3

There is no way to add a NuGet package into a project through Visual Studio Code nor through NuGet CLI.

And for the command nuget install (same function as nuget restore), it only downloads NuGet packages from the specified feed, but it does not make any changes for the project. You can also refer to the post How to install a NuGet package on the command line to a Visual Studio project.

The workarounds to add NuGet packages to project are as below:

  1. Add packages in Visual Studio

    You can open your project in Visual Studio, and then add NuGet packages through Visual Studio.

  2. Manually change project file

    If you have not Visual Studio installed. You can also manually change related files.

    Such as add the private feed into nuget.config file, and then change .csproj file with the lines like:

    <ItemGroup>
      <PackageReference Include="xxx" Version="xxx" />
    </ItemGroup>
    
  3. Add packages by the dotnet add package command

    You can also use dotnet add package command to add NuGet packages into your project:

    dotnet add [<PROJECT>] package <PACKAGE_NAME>  [-v|--version]
    
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Marina Liu
  • 32,805
  • 4
  • 48
  • 60