Dockerfile can’t see local file or private nuget server

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

  1. copy your system’s NuGet.Config in project folder at same root level where .csproject is.

  2. now in docker file put these statements just before you try to restore package:

    COPY ./NuGet.Config ./

  3. after that , append the config file location in dotnet restore command like this :

    RUN dotnet restore <CS_project_name>.csproj --configfile ./NuGet.Config

  4. Now do rest of the thing which you wanted to do .

  5. 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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)