To use both public and private NuGet package sources in your Visual Studio project, you need to configure NuGet to recognize both sources. Here’s how you can do it:
1. Open NuGet Package Manager Settings
- In Visual Studio, go to Tools > Options.
- Expand the NuGet Package Manager section and click on Package Sources.
2. Add Your Private Package Source
- Click the "+" button to add a new package source.
- Enter a Name (e.g., "My Private Source").
- Enter the Source URL or local path to your private NuGet feed.
- Click Update to save.
3. Ensure Both Sources Are Active
- Make sure both the official NuGet source (
https://api.nuget.org/v3/index.json) and your private source are listed and checked/enabled.
4. Installing Packages
When you open the Manage NuGet Packages dialog for your project, you can select which source to use from the Package source dropdown at the top. If you search for a package, Visual Studio will query all enabled sources. If packages with the same name exist in both, you can select the desired version/source.
5. Using nuget.config (Optional)
For source control or automation, you can define sources in a nuget.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MyPrivateSource" value="https://your-private-feed-url/" />
</packageSources>
</configuration>
- Place
nuget.configin your solution folder or user profile folder (%appdata%\NuGet\). - Visual Studio and
dotnetCLI will use these sources automatically.
6. Authenticating to Private Feeds
If your private source requires authentication, Visual Studio will prompt you for credentials the first time you access it. For Azure Artifacts feeds, you may need to sign in with your Azure account.