Skip to the content.

NuGet (.NET)

Make the proxy the only NuGet package source. The examples use the upstream name nuget; replace it with the name your operator gave the upstream (what you need).

   
Upstream type nuget
Package source https://proxy.example.com/v1/nuget/v3/index.json (the v3 service index)
Clients dotnet (NuGet)
Tested .NET SDK 8.0: in CI on every push and in the client lab. nuget.exe, Visual Studio and Paket: not tested.

Configure

NuGet.config — next to the solution, or the user-level one (~/.nuget/NuGet/NuGet.Config). <clear /> removes nuget.org and every inherited source, so the proxy is the only one:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="proxy" value="https://proxy.example.com/v1/nuget/v3/index.json" />
  </packageSources>
</configuration>

The source must be HTTPS. NuGet refuses the repository-signature resource of a plain-HTTP source.

Authenticate

NuGet cannot use a proxy that requires a token. NuGet sends the credentials of a package source (<packageSourceCredentials>) only in answer to a Basic challenge; the proxy challenges with Bearer, and NuGet has no setting for a request header. The restore fails:

error NU1301: Unable to load the service index for source https://proxy.example.com/v1/nuget/v3/index.json.

Where access control is on, the operator has to admit anonymous reads for the NuGet upstream (how).

Trust a private CA

.NET on Linux reads the CA bundle from the environment (on Windows and macOS it uses the system store):

export SSL_CERT_FILE=/etc/ssl/corp-ca.pem

SSL_CERT_FILE replaces the default bundle for the process: use a file that also holds the public CAs when the same process talks to other hosts.

Check that it works

dotnet restore app.csproj
dotnet nuget list source | grep -q "https://proxy.example.com/v1/nuget/v3/index.json"

dotnet nuget list source must show the proxy and nothing else.

Good to know

On the proxy

upstreams:
  nuget:
    type: nuget
    url: https://api.nuget.org

The service index and registration documents are served live with their same-host resources rewritten to the proxy (which is why server.publicUrl must be set); .nupkg files are cached immutably. Details: backends: nuget.