sdk: Dotnet restore fails to use the local Nuget.Config to retrieve nuget packages from private feeds while building docker image
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 16 (1 by maintainers)
I had the same issue but my file was capitalized “Nuget.confg” originally and changing it to “NuGet.Config” appears to have worked.
I had the same problem and I did something similar,
COPY NuGet.Config /root/.nuget/NuGet/This is still a problem in Linux. Ubuntu 18.04.
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.
robisonkarls solution didn’t work for me on .NET Core 3.1 SDK. My workaround is to build custom image for sdk
Dockerfile:
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
for the changes in custom image to work in gitlab-ci without caching.
This is very useful, I think because Linux file names are case sensitive.
@alohaninja I just confirmed:
myapp/.nuget/.nuget.config-dotnet restoreignoresmyapp/nuget.config-dotnet restoreuses itI am using docker for windows and linux containers. In the Dockerfile copy this statements:
RUN apt-get -y install gss-ntlmsspCOPY /NuGet.Config /root/.config/NuGet/My local
NuGet.Configfile is the following:I am actually using jenkins, so after the checkout stage, I just copy my
NuGet.Configfile inside the solution folder and rundotnet restore.Also experienced this issue with
dotnet restore- non-standard behavior coming from netframeworknuget.exewhere the standard path isroot/.nuget/nuget.config- we dropped the subdirectory why?Affirming the workaround is to move the
nuget.configfromroot/.nuget/nuget.configtoroot/nuget.configfor netcore. Maybe this was intentional. 🤔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.