Home > Enterprise >  What is the link between a nuget package and its source?
What is the link between a nuget package and its source?

Time:11-12

In my company, NuGet packages are coming from different sources:

When I start up Visual Studio, I get logged in automatically (at the above right corner, I can see my login settings).

I have access to some NuGet packages and there are some where I don't have access to:

  • Company.Something.UA : OK
  • ControlzEx : OK
  • DevExpress.Chartsv18.2_Core : NOK

I have been doing NuGet restore in lots of ways: normal commandline, developer prompt, using the standard NuGet.exe, using the latest NuGet.exe, from within the company network, from outside the company network, ..., it does not make any difference.

In order to pinpoint the problem, I was thinking of restoring a single NuGet package, which should come from one specific package source, but what is that source?
When checking the properties of NuGet packages (being OK or not), the package source is not mentioned.

So I would like to do:

NuGet.exe restore DevExpress.Chartsv18.2_Core DevExpress..._Core_Package_Source
  • How can I do that?
  • How can I know from which package source I need to download a specific NuGet package?

CodePudding user response:

There is no link. Package restore searches all sources in nuget.config (either system-defined or project-defined) for a package, in the order those sources are specified, and installs the first matching package it finds.

What you're really asking is "how do I install a package from a specific source", and you can do that with dotnet restore. Note that NuGet.exe is legacy and deprecated; its package restore functionality is integrated into the dotnet tool and improved there.

> dotnet restore MyPackage -s NugetSourceName

There is no way to know which source a package is available in without browsing it, but as stated above it shouldn't matter; package restore will figure it out.

CodePudding user response:

Now (with .NET 6 tooling) you do have a way to pin packages (patterns) to specific packages sources which is also called package source mapping:

  • Related