NuGet Packaging: Multiple & Custom Nuget Registries
How to setup multiple package source feeds in multiple ways
Dec 16, 2023
Engineering
NuGet Packaging Series
This article is part of the Creating NuGet Packages series. You can find the complete list of articles in the series at the end.
Introduction
In continuation of the previous article about publishing NuGet packages, this article describes configuring IDEs and a .NET project to fetch NuGet packages from multiple NuGet feeds. This includes official NuGet.org feeds, private (GitHub) feeds, and local directories.
Using JetBrains Rider
In Rider, open the Nuget Window and:
- Select Feeds tab 
- Add a new repository by clicking the - +and specifying the feed properties
Adding Local or Shared Directories
To add local or shared directories on your disk, set the feed properties as follows:
- Nameis the name of the feed as you see fit.
- URLis the disk path where you are storing NuGet packages.

Adding GitHub NuGet Package Feed
Adding GitHub Packages requires a bit more effort, but it is still a straightforward process.

Where:
- Name is the name of the feed as you see fit. 
- URLis the URL of your GitHub Packages feed. The format is- https://nuget.pkg.github.com/USERNAME/index.jsonwhere- USERNAMEis your GitHub username or organization name under which the repository resides.
- Useris your GitHub username or organization name under which the repository resides.
- Passwordis your Personal Access Token (PAT) generated on GitHub for the GitHub Packages feed. This is NOT your GitHub password.
Using Visual Studio
- Right-click on the solution in Solution Explorer. 
- Choose "Manage NuGet Packages for Solution." 
- Click on "Settings" or the gear icon. 
- Under "Package Sources," click the "+" button to add a new source. 
The rest is the same as we did in JetBrains Rider.

Manually adding using Nuget.config
Using nuget.config: You can manually edit or create a nuget.config file at the solution, project, or user profile levels.
While solution and project-level package repositories are simple as you place nuget.config either in the solution or project directory; if you want to add the local package repository on a user profile level on Windows, you will have to dig into the User/AppData directory where the path is usually:
C:\Users\{Name of the User}\AppData\Roaming\NuGet\NuGet.Config
Here's how the configuration can look:
If you're using a local path, it's important to note that the path can be either an absolute path or a relative path from the location of the nuget.config file.
> Remember to be cautious when storing credentials in nuget.config, especially if this file is checked into a public version control repository. Using environment variables or other mechanisms to keep secrets out of your source code is a good practice.
> NOTE: You can also add a custom nuget.config in the same directory where the .sln file is and will be additionally used when that particular solution runs.
Using the NuGet CLI
You can also add, remove, and manage package sources using the NuGet CLI:
To add a source
To add a source with a Password or PAT
Replace YOUR_USERNAME with your username and YOUR_PERSONAL_ACCESS_TOKEN with your Personal Access Token or password.
Please note it's important to be cautious when using the -Password option in the CLI, especially on shared or public systems, as it can expose sensitive credentials in the command history or logs.
To list all sources
To remove a source
Order of Execution
When you have multiple sources, NuGet will try to fetch packages from all of them according to the order specified in the configuration.
If multiple sources contain the same package version, NuGet will fetch it from the first source where it is found.
What Have We Learned?
Providing multiple source feeds for NuGet packages is a straightforward and adaptable process that can be accomplished in various ways to meet different needs.
In this article, we learned how to consume from multiple NuGet feeds using:
- JetBrains Rider 
- Visual Studio 
- global - NuGet.Config
- the - nugetCLI
Example Project on GitHub
An example project for this article can be found here:
Creating NuGet Packages Series
This article is part of the Creating NuGet Packages series. If you enjoyed this one and want more, here is the complete list in the series:
Happy Coding!




