How to disable a Nuget Feed in a .NET project

Most of us use private feeds in NuGet for storing our NuGet Packages. However, some projects might have stricter security restrictions that others, making it necessary to disable certain feeds to avoid using them as references.

To “blacklist” feeds, you can use the following configuration:

  1. Copy the default NuGet.Config file from C:\Users\XXX\AppData\Roaming\NuGet and paste it into your Visual Studio solution folder. This way, the configuration in the new NuGet.Config will overwrite the default one.

  2. Open the file and remove the URLs of the packageSources you do not want in the project.

  3. Add the keys from the removed packageSources into a new disabledPackageSources section.

The new Nuget.Config file should now look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <disabledPackageSources>
        <add key="XXXX" value="true" />
        <!-- Add other feeds you want to disable -->
    </disabledPackageSources>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <!-- Add other feeds you want to keep -->
  </packageSources>
  <!-- Remaining configuration -->
</configuration>
comments powered by Disqus