Tuesday, April 25, 2017

Add extra NuGet Repositories through nuget.config

By default Visual Studio has one NuGet source registered out of the box, the official NuGet gallery at https://www.nuget.org/.

However I had to use a package that wasn’t hosted on the official NuGet gallery but instead could be found on MyGet.org(https://www.myget.org/). Problem was that I didn’t want to ask all developers to register an extra Package Source in Visual Studio.

So what’s the alternative?

The trick is to add a nuget.config file to your solution.

From the documentation:

The behavior of every NuGet command, whether issued from the command line, the Package Manager UI, or the Package Manager Console, is driven by the accumulated settings from any number of NuGet.Config files:+

  • Project-specific NuGet.Config files located in any folder from the solution folder up to the drive root. These allow control over settings as they apply to a project or a group of projects.
  • A solution-specific NuGet.Config file located within a .nuget folder in the solution. Settings in this file apply only to solution-wide packages and is supported only in NuGet 3.3 and earlier. It is ignored for NuGet 3.4 and later.
  • The global config file located in %APPDATA%\NuGet\NuGet.Config, which is always used unless you specify a different config file using the -configFile switch on any NuGet command

Inside this nuget.config you can register extra package sources:

No comments: