【发布时间】:2020-03-18 19:26:40
【问题描述】:
当运行 'docker build . -t project' 我得到这个错误:
Step 6/10 : RUN dotnet publish -c Release -o out
---> Running in 73c3f5fa9112
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 55.93 ms for /app/Backend.csproj.
/usr/share/dotnet/sdk/3.1.200/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Pa
ckage Microsoft.CodeAnalysis.Analyzers, version 2.9.8 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet r
estore might have only partially completed, which might have been due to maximum path length restrictions. [/app/Backend.csproj]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
我的 Dockerfile 看起来像这样:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
# Command used to start the project
ENTRYPOINT ["dotnet", "Project.dll"]
我已安装来自 NuGet 的错误消息中列出的包。当我在终端中运行命令“dotnet publish -c Release -o out”时它可以工作,但是在 Dockerfile 中运行它总是失败。有什么想法吗?
我的包参考:
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.8" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
运行 dotnet restore 的输出:
Step 4/10 : RUN dotnet restore
---> Running in 1f26d6ac4244
Restore completed in 47.46 sec for /app/Backend.csproj.
Removing intermediate container 1f26d6ac4244
---> f1a2994a2704
【问题讨论】:
-
嗨 Ahaglund,欢迎来到 StackOverflow!我使用模板 asp.net 核心 Web 应用程序、nuget 包和您的 Dockerfile 进行了快速测试,它似乎对我有用。可能存在依赖关系解析问题。您是否有完整的 repro(包括项目)或者您能否列出 csproj 中的所有 PackageReference 项?
-
你能把
RUN dotnet restore的输出也加进去吗? -
嗨,马丁和奥马尔!我在原始消息中添加了 PackageReference 项目的列表和 RUN dotnet restore 的输出,因为它太长了,无法发表评论。谢谢!
标签: c# docker asp.net-core .net-core nuget