Solving Dotnet Restore Error 407 (Unauthorized)
The Problem
While working on a project which is being developed at the location of the client i ran into an annoying issue. The mandatory corporate web proxy is probably to blame.
dotnet restore
for .NET Core projects started producing 407 (Unauthorized) errors, which sucks a lot because restoring packages is an essential step of building the project.
[14:40:12][Step 1/1] Restoring packages
[14:40:15][Step 1/1] Restoring packages for C:\BuildAgent\work\638151be47d2c658\Project1.csproj...
[14:40:15][Step 1/1] Restoring packages for C:\BuildAgent\work\638151be47d2c658\Project2.csproj...
[14:40:15][Step 1/1] C:\Program Files\dotnet\sdk\2.1.300\NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\BuildAgent\work\638151be47d2c658\Solution1.sln]
[14:40:15][Step 1/1] C:\Program Files\dotnet\sdk\2.1.300\NuGet.targets(114,5): error : Response status code does not indicate success: 407 (Unauthorized). [C:\BuildAgent\work\638151be47d2c658\Solution1.sln]
I got the same error in a slightly different form as well.
[11:15:03][Step 1/1] Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/autofac.extensions.dependencyinjection/index.json'.
[11:15:03][Step 1/1] Response status code does not indicate success: 407 (Unauthorized).
[11:15:03][Step 1/1] Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/system.security.cryptography.cng/index.json'.
[11:15:03][Step 1/1] Response status code does not indicate success: 407 (Unauthorized).
[11:15:03][Step 1/1] C:\Program Files\dotnet\sdk\2.1.300\NuGet.targets(114,5): error : Failed to retrieve information about 'Autofac' from remote source 'https://api.nuget.org/v3-flatcontainer/autofac/index.json'. [C:\buildAgent\work\a2846c1c6e7d5294\Solution2.sln]
[11:15:03][Step 1/1] C:\Program Files\dotnet\sdk\2.1.300\NuGet.targets(114,5): error : Response status code does not indicate success: 407 (Unauthorized). [C:\buildAgent\work\a2846c1c6e7d5294\Solution2.sln]
The Solution
I found one machine that was still able to build the project. It had version 2.1.201
of the .NET Core SDK installed.
The broken machines had version 2.1.300
.
I downgraded all machines to .NET Core SDK version 2.1.201
and the problem was gone.
Other Things I Tried
Configure proxy authentication for nuget
The HTTP error code 407 litterally means Proxy Authentication Required
.
In my case the nuget proxy is configured in c:\users\{username}\AppData\Roaming\Nuget\NuGet.Config
but there are more possible locations
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Internal Package source" value="http://nuget.internal.nl/nuget" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<config>
<add key="http_proxy" value="http://proxy:8080" />
<add key="http_proxy.user" value="DOMAIN\USER" />
</config>
</configuration>
Remove all cached packages
Running nuget locals all -clear
and/or dotnet nuget locals all --clear
It did not help.