0

I am trying to build and push a docker image. This is giving me an error error NU1301: Unable to load the service index for source

The folder structure is as follows: src/appfolder/ In the appfolder I have the Dockerfile and nuget.config

The next two tasks I am trying to use are:

  - task: DockerInstaller@0
    inputs:
      dockerVersion: '17.09.0-ce'

  - task: Docker@2
    inputs:
      containerRegistry: '$(dockerRegistryServiceConnection)'
      repository: $(imageRepository)
      command: 'buildAndPush'
      Dockerfile: $(dockerfilePath)
      tags: 'latest'
      buildContext: '$(Build.SourcesDirectory)/src'

See Docker and nuget.config files

Docker:

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


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY . .
RUN dotnet restore "./appfolder/app.csproj"
WORKDIR "/src/appfolder"
RUN dotnet build "./app.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./app.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "app.dll"]

nuget.config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="Feed name" value="https://companyname.pkgs.visualstudio.com/project name/_packaging/feedname/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <companyname>
      <add key="Username" value="my username" />
      <add key="ClearTextPassword" value="my own PAT" />
    </companyname>
  </packageSourceCredentials>
</configuration>

In the Feed Settings -> permissions tab I have both of the service users addded as a Feed publisher (contributor).

I tried a lot of options, but I started with the one I described here.

1 Answer 1

1

I can reproduce the same error when using your nuget.config file. In your nuget.config file, the key of your Azure Artifact package source is "Feed name" but your packageSourceCredentials is configured for another source named "companyname". To resolve the issue, modify your packageSourceCredentials as shown below.

  <packageSourceCredentials>
    <Feed name>
      <add key="Username" value="my username" />
      <add key="ClearTextPassword" value="my own PAT" />
    </Feed name>
  </packageSourceCredentials>

See the details about package source session in the nuget.config file from Package source sections.

Then, modify your Dockerfile from RUN dotnet restore "./appfolder/app.csproj" to RUN dotnet restore "./appfolder/app.csproj" --configfile "./appfolder/nuget.config". Also, add --no-restore to your dotnet build and dotnet publish command.

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

4 Comments

Hi thank you for your answer. I made the change, but still facing the same error. /src/appname/appname.Core.csproj : error NU1101: Unable to find package packagename. No packages exist with this id in source(s): nuget.org [/src/appname.Subscriber/appname.Subscriber.csproj] i am do not see where I make the mistake
Hi @Sergio, according to this new error, it is trying to download packages from nuget.org instead of your Azure Artifact, so that the pipeline can't find your target packages. Please modify your Dockerfile from RUN dotnet restore "./appfolder/app.csproj" to RUN dotnet restore "./appfolder/app.csproj" --configfile "./appfolder/nuget.config". Also, add --no-restore to your dotnet build and dotnet publish command.
Yes this is working. Thank you very much. Is there a best practice to disable plain text PAT and istead of that making use of a secret variable from the devops library?
1. You can pass the PAT as a build argument to the Dockerfile. Add ARG PAT to your Dockerfile. 2. In your nuget.config file, use an environment variable for the password. <add key="ClearTextPassword" value="%PAT%" />. 3. When you build the Docker image in your pipeline, pass the PAT as a build argument. buildArguments: '--build-arg PAT=$(myPat)'.

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.