aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Sibling project references and solution-level NuGet.config not supported by Dockerfile and docker build

Open kcraft opened this issue 11 years ago • 2 comments

This isn't really a bug, but it might be a design consideration.

I have a solution with two projects and a custom NuGet.config file. Example:

.
+-- /NuGet.config (contains two package sources)
+-- /src
|   +-- Project1
|   +-- Project2
|   |   +-- project.json (lists "Project1" as a dependency)
|   |   +-- Dockerfile

Running "dnu restore", "dnu build", and "dnx kestrel" from within the Project2 directory all work correctly. However, running "docker build -t project2 ." from within the Project2 directory causes several problems. This is my Dockerfile:

FROM microsoft/aspnet:latest

ADD . /app
WORKDIR /app

RUN ["dnu", "restore"]

EXPOSE 5004
ENTRYPOINT ["dnx", "kestrel"]

The first problem is that my NuGet.config file is not used by "docker build" since it is located outside of my project directory, and docker does not access any files outside of the scope of the directory the Dockerfile is in. This causes "dnu restore" to fail since it does not look for packages in my custom NuGet package source and is unable to resolve the dependencies that don't exist on nuget.org.

The workaround kind of sucks but it is manageable: I can simply modify my Dockerfile to pass in my NuGet sources to "dnu restore". Here's the result:

FROM microsoft/aspnet:latest

ADD . /app
WORKDIR /app

RUN ["dnu", "restore", "-s", "https://my-custom-source", "-s", "https://api.nuget.org/v3/index.json"]

EXPOSE 5004
ENTRYPOINT ["dnx", "kestrel"]

That solves the first problem. But now I have another problem: "dnu restore" cannot resolve the dependency on Project1 since it is also outside of docker's scope.

I don't think there is a clean way to fix this problem without making Project1 its own NuGet package and pushing it to the custom package source. I have good reasons for putting Project1 in the same solution as Project2, so that is a situation I would prefer to avoid.

Unfortunately, I don't really have any suggestions for fixing this issue right now. However, considering that containers seem to be the wave of the future, I doubt I will be the last person to consider this an important issue.

kcraft avatar Nov 02 '15 03:11 kcraft

It also appears that I can move my NuGet.config file into the project directory (alongside Dockerfile) and that prevents me from having to include my NuGet sources inside the Dockerfile.

kcraft avatar Nov 02 '15 16:11 kcraft

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

aspnet-hello avatar Dec 31 '17 20:12 aspnet-hello