Search code examples
c#.netnugetnuget-package-restorenuget-server

NuGet servers on different networks


I have a project that has dependency to some nuget package. This nuget package exists on both nuget1 and nuget2 servers. The issue is that the servers are located on different networks. I have only one available at the same time. When restoring tries to connect to unavailable nuget1 server it says 404 and fails. It doesn't try to restore from nuget2. How can I solve the issue? Can I ask nuget to use nuget2 in case nuget1 is unavailable?


Solution

  • All configured NuGet package sources must be available for package installation and restore to work.

    From GitHub: package resolution fails if unreachable source exists:

    For example imagine the server is intermittently off, and it has a new version of xunit. As a user you will get quietly an inconsistent experience between multiple installs.

    This seems simple enough when you install a single package with no dependencies, but get quickly out of hand when you have a reasonably large package graph, that would lead you to losing days.

    So one option could be to use the same DNS name for both servers, and let the network admin register that name on each network pointing to the appropriate server.

    So on network 1, a DNS alias nugetserver exists and points to 10.0.0.1, and on network 2 a DNS alias nugetserver points to 192.168.1.1.

    Then in Visual Studio, you configure one server, namely nugetserver, as a package source.