【问题标题】:How to add NuGet packages to the Dockerfile build steps?如何将 NuGet 包添加到 Dockerfile 构建步骤?
【发布时间】:2018-02-06 12:19:59
【问题描述】:

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

我试过了:

  • 添加 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]

【问题讨论】:

  • 在我的情况下,我只有 RUN dotnet restore 并且它有效。当您运行 COPY . . 时,您在正确的文件夹中吗? dotnet restore 的输出是什么
  • 编辑了 COPY 行。当我添加 RUN dotnet restore 时,我得到输出:Restore: Nothing to do. None of the projects specified contain packages to restore. Done Building Project "C:\app\MessageProcessor.csproj" (Restore target(s)).
  • 原谅我的无知,但这不是 .NET 核心而不是完整的 .NET 框架,因此不使用 dotnet 来构建项目吗?
  • @GregorySuvalian 该应用基于 .NET Framework 4.6.2 项目。我希望使用 .NET Core 是一种选择...

标签: .net docker docker-for-windows windows-container


【解决方案1】:

想通了。

MSBuild (RUN ["dotnet", "restore"]) 不恢复 NuGet 包,原因解释为 here。所以我开始使用 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 容器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    相关资源
    最近更新 更多