Home > other >  Dotnet build for private nuget packages fails with "Unable to load the service index for source
Dotnet build for private nuget packages fails with "Unable to load the service index for source

Time:10-06

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

The access to the private package repo

My Package sources looks like this: My Package sources

CodePudding user response:

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.

  • Related