I have a .NET7 webapi project that is being built as a Docker container.
The project is referencing NuGet package(s) that are published to a private Azure DevOps (on-prem hosted) NuGet feed. Project contains a NuGet.config file where this feed is defined and credentials for the feed. Credentials are a Personal Access Token that was generated through Azure DevOps UI.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="MyFeed" value="https://.../nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="docker" />
<add key="ClearTextPassword" value="PAT_generated_in_devops" />
</MyFeed>
</packageSourceCredentials>
</configuration>
Dockerfile contents:
FROM mcr.microsoft.com/dotnet/sdk:7.0.203-alpine3.17 AS build
WORKDIR /src
# Copying all .csproj files here
# ...
COPY ./NuGet.config .
RUN dotnet restore "HttpApi.csproj" -r linux-x64
RUN dotnet publish "HttpApi.csproj" -c Release -r linux-x64 --self-contained true --no-restore -v:m -o /app -p:PublishReadyToRunComposite=true -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine
WORKDIR /app
COPY --from=build /app .
EXPOSE 8080
ENTRYPOINT [ "HttpApi" ]
Executing Dockerfile command that contains
RUN dotnet restore ProjectName.csproj -r linux-x64 fails with error message: error NU1301: Unable to load the service index for source https://.../nuget/v3/index.json
I tried setting up my domain credentials as packageSourceCredentials for the NuGet feed.
I tried setting HTTP_PROXY and HTTPS_PROXY as docker build arguments. I tried installing a local version of Azure DevOps Express 2022 to eliminate networking issues and connecting to the local NuGet feed. None of these solved the issue.
EDIT 1:
- NOTE 1: It's worth noting that dotnet restore works normally when run through Windows PowerShell or through Visual Studio. Issue occurrs when the project is being built by Docker.
- NOTE 2: Docker engine is utilizing WSL
The only solution that I managed to get to work was utilizing artifacts credentials provider as stated here: Artifacts credentials provider documentation. I also had to explicitly set
-s FEED_URIargument on thedotnet restorecommand, although the source is also defined in the nuget.config file.EDIT 1
Solution consists of:
nuget.configfile located in the solution roota. RUN command that downloads and execute the artifacts credentials provider shell script (Linux) during Docker build to install the nuget plugin
b. copy
nuget.configfile to build stagec. set the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable (replace
feed_urlwith Azure DevOps feed URI andpersonal_access_tokenwith Azure DevOps PAT)d. add
-s feed_uriargument todotnet restorecommand