0

I'm building a .NET Framework 4.8 class library in a Docker file. The class library is referencing Entity Framework 6.4.4. My solution builds ok in Visual Studio 2019 on my laptop.

The Docker file:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8

WORKDIR C:\src\lib\MyClassLib
COPY src\lib\MyClassLib\ .
RUN nuget restore packages.config -PackagesDirectory ..\..\packages
RUN msbuild MyClassLib.csproj

The NuGet restore step seems to go well:

Added package 'EntityFramework.6.4.4' to folder 'C:\packages'

But in the next step that does the build, the EntityFramework reference could not be found.

This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\..\packages\EntityFramework.6.4.4\build\EntityFramework.props.

Based on the folder structure, the relative path to the packages folder in .csproj should end up in C:\packages. The file that it is complaining about, is actually present. I inspected it using RUN dir C:\packages\EntityFramework.6.4.4\build in the Docker file.

How can I fix this?

ngruson
  • 1,176
  • 1
  • 13
  • 25

1 Answers1

1

I believe that the error may come from the definition of your directories.

The WORKDIR command refers to the working directory in the container you are creating, not a path in your original file system (reference), so, when you define WORKDIR C:\src\lib\MyClassLib, you are actually creating that directory in the container, not pointing to your file system. (I have other details on this here)

Maybe you want to do something like:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8

WORKDIR "/src/lib/MyClassLib" # workdir that receives the copy below
COPY src\lib\MyClassLib\ .

WORKDIR "/packages" # workdir to receive the packages
COPY packages . # copy into the workdir
RUN nuget restore packages.config

WORKDIR "/src/lib/MyClassLib" # workdir that contains your csproj - I don't know if it is actually here
RUN msbuild MyClassLib.csproj

[EDIT] I don't know if you intend to copy folders' content recursively or not. Either way, you may find information here

I am sorry if this snippet is not actually accurate, but it is more of a "way to go" with the information I got, than a final solution. Hope it helps though :)

nunohpinheiro
  • 2,169
  • 13
  • 14
  • I was already aware that C:\src was pointing to the file system of the container image, not to my local path. However, your suggestion actually worked! All I did was change the WORKDIR lines to relative paths rather than C:\src. But I don't understand why yet. Does this make sense? – ngruson Jan 10 '21 at 18:43
  • Glad it helped :) In Docker, the relative paths may actually be defined without the slash, as show in this definition https://docs.docker.com/engine/reference/builder/#workdir – nunohpinheiro Jan 11 '21 at 00:19