enzi
enzi

Reputation: 4165

Stop VisualStudio from using a particular NuGet package source

My workplace has a NuGet server which I have configured on my personal PC when I work from home. It is only reachable when I connect to my workplace via VPN.

When I'm working on personal projects I don't want to always establish the VPN connection first, as I don't need the NuGet server from work.

However, when I don't do that, VisualStudio / NuGet package manager will always try to contact it to search for packages or resolve dependencies, even when I explicitly choose the package source from the UI dropdown menu. This also manifests in timeout related errors when I try to install a package with a specific source selected.

As things stand, I either have to connect via VPN or uncheck he package source – which is a global setting. Isn't there a way to tell NuGet to only use a specific package source or turn sources on/off for specific solutions?


Solution for my specific use case:
After @jessehouwing pointed me to the NuGet docs, I ended up putting a NuGet.Config file in the top-level repository folder where all my work-related solutions are stored.

All the file does is add a packageSource, all other settings are taken from the global settings file (the one VisualStudio uses is in %appdata%/NuGet), from which I removed the work-specific package source so it doesn't bother me in personale projects.

In case someone needs it:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Work" value="http://path/to/your/source" />
  </packageSources>
</configuration>

Upvotes: 1

Views: 365

Answers (1)

jessehouwing
jessehouwing

Reputation: 114681

You can stick a nuget.config in the solution folder:

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.

Then put the correct repository locations in there.

Upvotes: 1

Related Questions