I have a build for a .NET solution that is running in a private agent. The solution contains both .NET Core 2.1 and .NET Standard 2.0 projects.
Some of the nuget packages installed are the following:
The build fails when trying to restore the nuget packages with the following error:
"F:\Agent01\w\141\s\xxxxxxx.sln" (Restore target) (1) -> (Restore target) -> C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error : Unable to load the service index for source https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json. C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized).
Build task is the following:
This is the content of %appdata%\NuGet\nuget.config
file in the build agent:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MyFeed" value="https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="LocalBuildAgent" />
<add key="ClearTextPassword" value="xxxxxxxxxxx" />
</MyFeed>
</packageSourceCredentials>
</configuration>
I already checked a few similar questions but so far I wasn't able to find a solution for my problem.
Some notes:
What am I missing? How to fix this issue? Why can't I restore the packages using the dotnet restore
command?
Packages are restored without errors when using the old Nuget Restore task as follows:
I am able to restore the packages using the .NET Core task v1:
Or using v2 task with argument --force
:
I found a solution - add the following package source to %appdata%\NuGet\nuget.config
:
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
Complete file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MyFeed" value="https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="LocalBuildAgent" />
<add key="ClearTextPassword" value="xxxxxxxxxxx" />
</MyFeed>
</packageSourceCredentials>
</configuration>
Also, check Regression in .NET SDK 500: 'dotnet tool install' fails with 401 (Unauthorized) when there is a private feed in NuGet.config #7524. This problem seems to be caused by .NET SDK 2.1.500.
Another workaround would be to uninstall that version:
The issue is not present in .NET Core SDK 2.1.400, e.g. it goes away when .NET Core SDK 2.1.500 is uninstalled, and reappears when SDK 2.1.500 is installed again.