Search code examples
visual-studionugetgithub-package-registry

Get Visual Studio to Use Private Package Registry


I've created a solution that uses multiple class library projects with their own GitHub repositories and Visual Studio correctly recognizes each project's repo and commits changes to each project's own GitHub repository.

Additionally, each class library project has a nuget.config file in its root that tells it where to get Nuget packages from and some of the Nuget packages are from my private package registry on GitHub.

Everything works fine individually because when I make changes to them, I simply commit them to their respective GitHub repositories after making any Nuget reference changes. Then GitHub actions kick in and create new versions of their Nuget packages.

However, in my new solution that references a few of these class libraries, Visual Studio doesn't seem to restore any of the packages from my private package registry. It looks like the nuget.config files in each project's root have no effect on helping Visual Studio finding my packages.

How do I need to set up Visual Studio and/or my new solution using these class libraries so that when I open the solution, all the Nuget packages are restored, whether they come from Nuget.org or my private package registry on GitHub?

BTW, I'm on the latest version of Visual Studio i.e. 17.8.0 on Windows.


Solution

  • NuGet's official documentation explains: https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior

    In a solution folder, settings apply to all projects in subfolders. Note that if a config file is placed in a project folder, it has no effect on that project. When restoring a project on the command line, the project's directory is treated as the solution directory, which can lead to differences in behaviour when restoring the project vs solution.

    So, you have to move the nuget.config file to the solution directory. nuget.config files in project directories are not loaded.