用docker构建一个dotnet应用; “找不到资产文件'/obj/project.assets.json'”

时间:2019-11-11 13:29:49

标签: docker .net-core

我有一个用于dotnet应用程序的docker构建。在较高级别,docker文件具有以下步骤:

  1. 第1层:
    1. 仅还原Web应用程序项目
    2. 构建Web应用程序项目
  2. 第2层:
    1. 还原整个解决方案
    2. 构建并运行测试
  3. 第3层:
    1. 发布Web应用程序项目
  4. 第4层:
    1. 运行Web应用程序的入口点

这是dockerfile的内容:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
ARG VERSION=0.0.3
ARG RELEASENOTES
ARG PROJECT
ARG ASSEMBLYNAME

WORKDIR /app
COPY . .

RUN dotnet restore $PROJECT

RUN dotnet build -c Release --no-restore $PROJECT


FROM build as test

RUN dotnet restore

RUN dotnet test -c Release --filter FullyQualifiedName!~$PROJECT.IntegrationTests


FROM build as publish

RUN dotnet publish -c Release -o out --no-build $PROJECT


FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime

COPY --from=publish /app/out ./

ENTRYPOINT ["dotnet", "$ASSEMBLYNAME.dll"]

一切正常,直到发布步骤出现错误:

/usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file '/app/Service.UnitTests/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/Service.UnitTests/Service.UnitTests.csproj]
  PayPalClient -> /app/out/
/usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file '/app/PayPalClient.IntegrationTests/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/PayPalClient.IntegrationTests/PayPalClient.IntegrationTests.csproj]
/usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file '/app/PayPalClient.UnitTests/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/PayPalClient.UnitTests/PayPalClient.UnitTests.csproj]

我知道这是说我尚未还原这些项目,但我不想还原它们。它们是测试项目,不应成为最终输出的一部分。

对于它的价值,我可以在命令行中运行这些命令,就像在此dockerfile中一样,并且一切正常。我看到此错误只是docker build的一部分。

我在做什么错了?

0 个答案:

没有答案