NuGet package sources are stored in a NuGet.Config file that can be stored in three different places:
- User profile
- With the solution itself.
- Machine wide in ProgramData: %ProgramData%\NuGet\Config*.config
For the user profile the package sources are stored in the file:
%AppData%\NuGet\NuGet.Config
When you add the package source in Visual Studio this is where the package source will be saved.
For each solution Visual Studio will look in several directories for the NuGet.Config file before using the one from the user's profile. With a solution in the directory c:\Projects\MySolution then NuGet will look for this file in the directories:
- c:\Projects\MySolution.nuget\nuget.config
- c:\Projects\MySolution\nuget.config
- c:\Projects\nuget.config
- c:\Projects\nuget.config
- c:\nuget.config
Machine wide package sources are shown in the Machine-wide section of the dialog in Visual Studio. Visual Studio will look in following directories:
- %programdata%\NuGet\Config\IDE\Version\SKU*.config
- %programdata%\NuGet\Config\IDE\Version*.config
- %programdata%\NuGet\Config\IDE*.config
- %programdata%\NuGet\Config*.config
- %ProgramData%\NuGet\Config\IDE*.config
- %ProgramData%\NuGet\Config*.config
Note that IDE will be replaced with VisualStudio. The Version will be replaced by the Visual Studio version number. The SKU will be replaced with Ultimate, Pro, Professional or Premium.
To programatically add package sources to an NuGet.Config file you could use NuGet.exe which allows you to add or update package sources using a command line similar to:
nuget.exe sources add|update -Name [name] -Source [source]
Or you can use another tool to update the XML in the NuGet.Config file.