2

I'm working on a C# project, having the following nuget.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear/>
        <add key="nuget"
             value="https://www.nuget.org/api/v2/"/>
        <add key="gitlab"
             value="https://localdomain/api/v4/projects/5/packages/nuget/index.json"/>
    </packageSources>
    <packageSourceCredentials>
        <gitlab>
            <add key="Username"
                 value="MyUserName"/>
            <add key="ClearTextPassword"
                 value="MyToken"/>
        </gitlab>
    </packageSourceCredentials>
</configuration>

"MyToken" looks as follows: "glpat-".

It has been created, using menu item "Settings>Access Token" in my project.

During the build, the following error message is shown:

error NU1301: Unable to load the service index for source

The build is done, using the dotnet build command from a container, based on the following image: "mcr.microsoft.com/dotnet/sdk:6.0".

Does anybody have an idea?

Thanks in advance

Edit:
It seems to be a problem with the local domain as NuGet.org seems to work, there are no error messages.

For your information: localdomain is defined in /etc/hosts file.

In the runner's configuration file, a volume parameter is defined in order to link the auto-signed certificate. In top of that, a parameter, called extra host, is defined too for the DNS, corresponding with localdomain.

Hereby the dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Service.API/Service.API.csproj", "Service.API/"]
COPY ["Service.Application/Service.Application.csproj", "Service.Application/"]
COPY ["Service.Domain/Service.Domain.csproj", "Service.Domain/"]
COPY ["Service.Database/Service.Database.csproj", "Service.Database/"]
RUN dotnet restore "Service.API/Service.API.csproj"
COPY . .
WORKDIR "/src/Service.API"
RUN dotnet build "Service.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Service.API.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Service.API.dll"]

Edit2:
I'm working in a CI (Continuous Integration) environment, so the error message is not local on my computer.
While performing a curl to the mentioned address on the container, I get an error 401 (Unauthorised) although I have no problem surfing, using a browser. The 401 error message is also shown while performing curl, mentioning username and password.
As far as the corresponding token is concerned: it has full right/read access and is not expired.

3 Answers 3

1

It smells like a 401 Unauthorized issue to me.

I would try to take the index.json file and put it somewhere you 100% sure that you can access using CURL. ie. an HTTP link with no authentication or possibly a local file path. then work backwards.

From there, you can work to resolve the 401 error. It could be a locked account, IP restriction, bad password (case insensitive) etc. etc.

I'm thinking it would be related to the localdomain certificate or something along those lines. The TRUSTED ROOT AUTHORITY for the cert may not exist on your build. For example, our company moved from Verisign or Thwarte to ENTRUST... and it blew up all kinds of code everywhere because the entrust auth wasn't installed.

Anyway good luck. I think you need to start with HTTP and no auth, then add HTTPS and no auth, then HTTPS and auth. something like that.

Sign up to request clarification or add additional context in comments.

Comments

1

I Resolve it by Change LocalHost Address In My Nuget.config

Comments

0

According to that nuget.config file there are two problems I can see and they both have different solutions.

If the "https://www.nuget.org/api/v2/" source cannot be found then your container which is doing the building has no internet access. You will need to ensure that it does.

If the "https://localdomain/api/v4/projects/5/packages/nuget/index.json" source cannot be found then its possible that the container itself can't find the destination because its host file doesn't know where to look. My guess is that it's a FQDNS you setup locally that is hosting some nuget packages but the container that is used during building can't find it so it's throwing the error.

May help a little to give us some more info on the DockerFile that is used during the build process to build your app inside the container so that we can offer a clearer solution but this what I think might be causing the issue.

Note: You can circumvent all of this by copying the published data of your .NET project into the final container. Here's a post from another user who was trying something similar - Docker build for C# core need the internet connection

3 Comments

Thanks a lot, but the situation is a bit more complex. I've edited my question for further explaining.
one of the solutions I suggested is finish the publish on the local machine/devops runner and then copy that finalized app into the container. You wouldn't need to run the build inside the container or the publish inside it either. This is all hinged on the assumption that you dont want to do all that work in the container. You can take a look at what they did here, its very close to what you're looking for - stackoverflow.com/questions/36151981/…
Thanks for your reply, but the post you're referring to, deals with dynamically updating the /etc/hosts file, which is needed in order to be able to reach the hosts. My problem, as explained in my second edit, is about not having the authorisation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.