7

我有一个带有一些 NuGet 包引用的小型 .NET Framework 4.6.2 应用程序。执行时:docker build -t myapp .我收到错误:Could not resolve this reference.对于每个引用的 NuGet 包。

我试过了:

  • 添加RUN ["dotnet", "restore"]以从 .csproj 恢复包
  • 将图像标签更改为:4.6.2

如何将 NuGet 包添加到构建过程?

谢谢你的时间!

Dockerfile:

FROM microsoft/dotnet-framework-build:4.7.1 as build-env

WORKDIR /app
COPY . /app

RUN ["dotnet", "build"]

FROM microsoft/dotnet-framework:4.7.1
WORKDIR /app
COPY --from=build-env /app .

ENTRYPOINT ["MessageProcessor.exe"]

构建步骤中单个引用的完整错误:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "GreenPipes, Version=1.2.1.98, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\app\MessageProcessor.csproj]
4

1 回答 1

13

弄清楚了。

由于此处解释的某些原因, MSBuild( RUN ["dotnet", "restore"]) 不会恢复 NuGet 包。因此,我开始使用 nuget.exe 命令并最终奏效。

FROM microsoft/dotnet-framework-build:4.7.1 as build-env

WORKDIR /app
COPY . /app
RUN nuget.exe restore MessageProcessor.csproj -SolutionDirectory ../ -Verbosity normal
RUN MSBuild.exe MessageProcessor.csproj /t:build /p:Configuration=Release /p:OutputPath=./out

FROM microsoft/dotnet-framework:4.7.1
WORKDIR /app
COPY --from=build-env app/out .

ENTRYPOINT ["MessageProcessor.exe"]

这给我留下了一个干净而闪亮的 .NET Framework 4.6.2 Docker 容器。

于 2018-02-08T09:12:58.850 回答