Docker 构建找不到 EntityFramework.props

Docker build can't find EntityFramework.props

我正在 Docker 文件中构建 .NET Framework 4.8 class 库。 class 库引用了 Entity Framework 6.4.4。 我的解决方案在 Visual Studio 2019 年在我的笔记本电脑上构建正常。

Docker 文件:

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

NuGet 还原步骤似乎进展顺利:

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

但是在构建的下一步中,找不到 EntityFramework 引用。

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.

根据文件夹结构,.csproj 中 packages 文件夹的相对路径应该在 C:\packages 中结束。 它抱怨的文件实际上存在。我检查它使用 运行 目录 C:\packages\EntityFramework.6.4.4\build 在 Docker 文件中。

我该如何解决这个问题?

我认为错误可能来自您的目录定义。

WORKDIR 命令指的是您正在创建的容器中的工作目录,而不是原始文件系统中的路径(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 )

也许你想做这样的事情:

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

[编辑] 我不知道您是否打算递归复制文件夹的内容。无论哪种方式,您都可以找到信息

如果这个片段实际上不准确,我很抱歉,但它更像是我得到的信息的“方法”,而不是最终解决方案。希望它有所帮助:)