Sdk: Dotnet restore fails to use the local Nuget.Config to retrieve nuget packages from private feeds while building docker image

Created on 8 Mar 2017  路  15Comments  路  Source: dotnet/sdk

Steps to reproduce

add a Nuget.Config to your project with a private feed and run dotnet restore as part of docker build. Below is the basic Docker file that I am using.

FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 80
CMD ["dotnet", "run", "--server.urls", "http://*:80"]

Dotnet restore fails because it is not using the package sources from the nuget.config file inside the project. Below is the Nuget.Config file that I am using (mocking the private feed name).

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <packageSources>
    <clear/>
    <add key="private package source" value="http://artifactory.private.svc/artifactory/api/nuget/nuget-release-local" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Expected behavior

NuGet Config files used:
/root/appName/Nuget.Config
/root/.nuget/NuGet/NuGet.Config

Feeds used:
http://artifactory.private.svc/artifactory/api/nuget/nuget-release-local
https://api.nuget.org/v3/index.json

Actual behavior

NuGet Config files used:
/root/.nuget/NuGet/NuGet.Config

Feeds used:
https://api.nuget.org/v3/index.json

Environment data

dotnet --info output:

dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
Version: 1.0.1
Commit SHA-1 hash: 005db40cd1

Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /usr/share/dotnet/sdk/1.0.1

Most helpful comment

This is still a problem in Linux. Ubuntu 18.04.

All 15 comments

Below is the workaround I am using right now to fix this problem, as part of my docker build I am copying the local Nuget.Config to root Nuget.Config.

FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
**RUN ["cp", "Nuget.Config", "/root/.nuget/NuGet/NuGet.Config"]**
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 80
CMD ["dotnet", "run", "--server.urls", "http://*:80"]

/cc @emgarten @rohit21agrawal

Moved over to Nuget/Home.

I had the same problem and I did something similar,

COPY NuGet.Config /root/.nuget/NuGet/

Is there any update to this issue?
It's still broken and I have to copy the Nuget.Config as described.

This is still a problem in Linux. Ubuntu 18.04.

Battled this problem for hours attempting to build first docker container. The solution by @RobsonKarls was the ticket. I can't say that this is a bug, but rather a not very well documented Dockerfile script step. Dotnet restore needs all the files in the correct place, so if you don't script the preparation of the environment properly (e.g. Nuget.config), there is no chance it can work correctly. Having said that, this should be better described/documented so that others in this situation don't need to dig so deeply for the answer.

@RobsonKarls 's solution also worked for me... it was the only one that worked actually... tks!

Any updates on this? Still a problem.

docker --version
Docker version 18.09.2, build 6247962

Using image microsoft/dotnet:2.1-sdk

Also experienced this issue with dotnet restore - non-standard behavior coming from netframework nuget.exe where the standard path is root/.nuget/nuget.config - we dropped the subdirectory why?

Affirming the workaround is to move the nuget.config from root/.nuget/nuget.config to root/nuget.config for netcore. Maybe this was intentional. 馃

I had the same issue but my file was capitalized "Nuget.confg" originally and changing it to "NuGet.Config" appears to have worked.

@alohaninja I just confirmed:

  • myapp/.nuget/.nuget.config - dotnet restore ignores
  • myapp/nuget.config - dotnet restore uses it

This is still an issue with 3.0.100-bionic :/

I am using docker for windows and linux containers. In the Dockerfile copy this statements:
RUN apt-get -y install gss-ntlmssp
COPY /NuGet.Config /root/.config/NuGet/

My local NuGet.Config file is the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="mysource" value="http://source/nuget/" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSourceCredentials>
    <mysource>
      <add key="Username" value="user" />
      <add key="ClearTextPassword" value="pass" />
    </mysource>
  </packageSourceCredentials>
</configuration>

I am actually using jenkins, so after the checkout stage, I just copy my NuGet.Config file inside the solution folder and run dotnet restore.

robisonkarls solution didn't work for me on .NET Core 3.1 SDK. My workaround is to build custom image for sdk

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS base
RUN dotnet nuget add source https://local-nuget-server-url/v3/index.json -n LocalServer

So there is no need for hacky copying of NuGet.Config to each projects folder.

Also I had to force pull in build scripts by adding -- pull

docker build --pull ...

for the changes in custom image to work in gitlab-ci without caching.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

billpratt picture billpratt  路  70Comments

NinoFloris picture NinoFloris  路  99Comments

nathanboktae picture nathanboktae  路  104Comments

srikanthramamurthy picture srikanthramamurthy  路  88Comments

ericstj picture ericstj  路  54Comments