skip to Main Content

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:PthTosourcereposProjectsrcProject.nameProject.csproj  1   

With the popular resolution

Nuget connection attempt failed "Unable to load the service index for source"
I tried deleting %AppData%RoamingNuGetNuGet.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:PthTosourcereposProjectsrcProject.nameProject.csproj : error NU1301: Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. [C:PthTosourcereposProjectsrcProject.nameProject.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

2

Answers


  1. Chosen as BEST ANSWER

    I got a dirty solution.

    I decided to use private nuget repo username and password in the Nuget.Config ( at least locally ). I changed the Nuget.Config to:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <packageSources>
            <add key="MyGet" value="https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json" />
        </packageSources>
        <packageSourceCredentials>
            <MyGet>
                <add key="Username" value="myusername" />
                <add key="ClearTextPassword" value="mysecretpassword" />
            </MyGet>
        </packageSourceCredentials>
        <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>
    

    I deleted the NuGet.Config from NuGet folder by running NuGet Run

    Then, from VS Developer PowerShell Terminal ( because it is not working with the UI build tab ) I ran dotnet restore and the packages got restored.

    I'm looking for better answers to avoid passwords in clear text.


  2. 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 PanelUser AccountsCredential 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search