for those who have landed here as they were using private repositories or custom nuget feeds and RUN dotnet restore is failing ,then here is what you can do :
Applicable especially if : your NuGet.Config contains the private repo endpoint and credentials , then
-
copy your system’s NuGet.Config in project folder at same root level where .csproject is.
-
now in docker file put these statements just before you try to restore package:
COPY ./NuGet.Config ./ -
after that , append the config file location in dotnet restore command like this :
RUN dotnet restore <CS_project_name>.csproj --configfile ./NuGet.Config -
Now do rest of the thing which you wanted to do .
-
just at the end before entry point or before copying to other container(in case of multistage build) , it is good idea to remove NuGet.Config,as we don’t want that to be available in pod/container to be seen
RUN rm ./NuGet.Config
[Update] like mentioned at https://github.com/NuGet/Home/issues/4413#issuecomment-483920015
if we use the following copy command to put it in root of file system
COPY ./NuGet.Config /nuget.config
then we dont need to specify the location of config file during dotnet restore