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.
2
Answers
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:
I deleted the NuGet.Config from NuGet folder by running
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.
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
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.
I found it from the stackoverflow answer here: Nuget Package Source is not prompting for credentials