Search code examples
asp.net.netvisual-studiovisual-studio-2022nuget-package-restore

Dotnet build for private nuget packages fails with "Unable to load the service index for source https://privatenuget.org/F/packages/api/v3/index.json"


I have private nuget repo packages in my solution and when I restore them to build my app in Visual Studio, I get the following error

Severity    Code    Description Project File    Line    Suppression State
Error   NU1301  Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. MyPrivate.Project.Repository    C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj  1   

With the popular resolution

Nuget connection attempt failed "Unable to load the service index for source" I tried deleting %AppData%\Roaming\NuGet\NuGet.Config and restarting VS which is not working for me.

My Nuget.Config looks like this.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="MyGet.orgV3" value="https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageManagement>
    <add key="format" value="1" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

Even tried dotnet restore --interactive

But in futile

dotnet restore --interactive
  Determining projects to restore...
C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj : error NU1301: Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. [C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj]

The repo needs either a password/AzureAAD identity for access and I have logged into the visual studio/terminal with the account I have access to the private repo. I think this is somehow stopping the service index to load, but I have a roadblock to achieving it.

The access to the private package repo: The access to the private package repo

My Package sources looks like this: My Package sources


Solution

  • The issue was that I messed with the private package repository password that would be prompted when the VS loads the project. If you entered it wrong once, you would never get the package restored.(which is pathetic....as the reason for the restoration failure is not explicit.) But we can easily solve this by the following steps:

    If Visual Studio does not prompt for credentials but the logging Output shows that you did not authenticate correctly, then go to

    Control Panel\User Accounts\Credential Manager
    

    and click "Windows Credentials". You can remove stored credentials for nuget/github there. If they become invalid - for example because you regenerated a token - Visual Studio does not prompt to overwrite the invalid credentials, but after removing the credentials and restarting Visual Studio you do get the prompt.

    enter image description here

    I found it from the stackoverflow answer here: Nuget Package Source is not prompting for credentials