Calling do.net restore <project>
from my Dockerfile is resulting in a NU1301: Unable to load the service index for source
error. I've been going through many of the suggested similar questions and continue to have issues. Here is as much info about the things I've tried as I can provide:
RUN ping google.com
succeeds (so I can reach the inte.net) nuget.org
feedRUN curl <nuget_feed_url>
succeeds --verbosity detailed
doesn't provide any other error messages but the oneHere is the section of the Dockerfile in question
FROM mcr.microsoft.com/dotnet/aspnet:6.0.13 AS base
# Create dockeruser in base layer
RUN addgroup --system --gid 1000 dockergroup \
&& adduser --system --uid 1000 --ingroup dockergroup --shell /bin/sh dockeruser
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Arguments are required in each stage in order to get the correct value
WORKDIR /src
COPY ["src/Nucleus.LumberYard.API/", "Nucleus.LumberYard.API/"]
COPY ["./nuget.config", "./nuget.config"]
WORKDIR "/src/Nucleus.LumberYard.API"
#COPY [".editorconfig", "./"]
RUN dotnet restore "Nucleus.LumberYard.API.csproj"
RUN dotnet build "Nucleus.LumberYard.API.csproj" -c Release --no-restore
Environment info
Based on my understanding you have the following scenario:
do.net restore
command targeting one of your csproj
filedo.net restore
command fails because the do.net
cli is unable to talk with your private nuget feed I encountered the very same situation with the project I'm working on. We have a private Nuget feed hosted in Azure Devops and we too had some troubles figuring out how to solve this.
First of all, let's clarify the root cause of the problem. You did the right thing veryfying that you are able to reach the nuget feed from your build machine, via the curl
command you mentioned. What is actually failing is the authentication between your build machine and the private nuget feed.
The first thing you need is a personal access token with read permissions for your nuget feed. You can follow this guide to create the personal access token you need.
Once you have the token, you need to provide it to the do.net
cli. There are several ways to do so, I'm going to explain the one that worked for us.
Instead of adding the nuget source to the nuget.config
file, we registers it via a cli command. I'm quite sure there is a way to do exactly the same thing via the nuget.config
file (see here for more details).
This is the cli command we use inside of our docker file:
RUN dotnet nuget add source https://foo.bar.com/something/nuget/v3/index.json -u "whatever" -p "my-personal-access-token" --store-password-in-clear-text --valid-authentication-types "basic"
Notice that:
https://foo.bar.com/something/nuget/v3/index.json
is the absolute URL pointing to the index of your private nuget feed whatever
my-personal-access-token
must be substituted with the personal access token you have created as a first stepHere you can find the full reference for the do.net nuget add source
command.
After registering this source with the do.net
cli, you will be able to run your do.net restore
command with no errors.
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.