Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I specify a NuGet package comes from an external source in packages.config?

Tags:

nuget

I am working on a project that has a dependency on a NuGet project that is on an external source. We are using package restore and not committing packages into Git. For developers that do not have this source configured in their NuGet settings, is there a way to specify in the packages.config file that this package should be pulled from a different source?

e.g.,

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
  <package id="bootstrap" version="3.0.0" targetFramework="net45" />
  ...

  <!-- How do I specify that this custom package comes from a different source? -->
  <package id="MyCustomPackage" version="1.0.0" targetFramework="net45" />

  ...
  <package id="Respond" version="1.2.0" targetFramework="net45" />
  <package id="WebGrease" version="1.5.2" targetFramework="net45" />
</packages>
like image 834
Ken Sykora Avatar asked Jun 09 '14 16:06

Ken Sykora


People also ask

How do I change the source of a NuGet package?

To manage your package sources, select the Settings icon or select Tools > Options. In the Options window, expand the NuGet Package Manager node and select Package Sources. To add a source, select +, edit the Name, enter the URL or path in Source, and then select Update.

How do I reference a NuGet package?

After you install a NuGet package, you can then make a reference to it in your code with the using <namespace> statement, where <namespace> is the name of package you're using.

How do I add a reference from packages config?

Open the Package Manager UI - Right-click on References and select Manage NuGet Packages... Open the Package Manager Console - From Tools > NuGet Package Manager , select Package Manager Console. Run NuGet restore - Right-click on the solution node in the Solution Explorer and select Restore NuGet Packages.

How do I install NuGet external package?

Install packages from NuGet.orgSelect Package Manager, and then copy the Install-Package command. In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console to open the package manager console. Paste the command into the Package Manager Console and then press Enter.


1 Answers

Each user can have their own config file, where you can specify the location of the sources:

<packageSources>
        <add key="NuGet official package source" value="https://nuget.org/api/v2/" />
        <add key="TestSource" value="C:\Temp" />
</packageSources>

For more info, see docs here

You can also configure this at the project or solution level by adding a NuGet.config to the project or solution.

like image 180
Donal Avatar answered Oct 29 '22 18:10

Donal