【问题标题】:error NETSDK1064: Package DnsClient, 1.2.0 was not found错误 NETSDK1064:未找到包 DnsClient,1.2.0
【发布时间】:2020-04-12 04:53:29
【问题描述】:

我有一个 Asp.Net 核心 docker 映像。我最后一次尝试构建它是在 2 个月前。现在,我在尝试构建它时遇到了错误。

有什么想法吗?有什么东西破坏了 Microsoft docker 映像吗?当尝试在 Elasticbeanstalk 实例上发布和运行时,这也会中断。

完整的错误日志:

/usr/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package DnsClient, version 1.2.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/app/BacktraderDataApi.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 ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet", "myApp.dll"]

【问题讨论】:

    标签: docker asp.net-core dockerfile


    【解决方案1】:

    当使用--no-cache 之类的解决方案根本无法恢复时,通常表明来自主机的工件被复制到构建容器中。当主机和构建容器具有不同的 RID 时,这可能会导致问题。当运行 linux 容器时,这通常会发生在 Windows 机器上。 .NET Core Docker 示例建议使用 .dockerignore file 来避免使用 Dockerfile 处理 bin 和 obj 目录。

    【讨论】:

    • 这是一个最准确的答案。正如下面的答案所述,只需确保 .dockerignore 文件正确忽略 bin 和 obj 目录。
    【解决方案2】:

    根据https://github.com/microsoft/containerregistry/issues/20 上针对同一问题发布的信息以及此处的信息,我尝试了以下操作:

    1. dotnet new web
    2. 编辑 csproj 并添加以下内容:
      <ItemGroup>
        <PackageReference Include="MongoDB.Driver" Version="2.10.1" />
        <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
      </ItemGroup>
    
    1. 创建了以下 Dockerfile
    # https://hub.docker.com/_/microsoft-dotnet-core
    FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
    WORKDIR /source
    
    # copy csproj and restore as distinct layers
    COPY *.csproj .
    RUN dotnet restore
    
    # copy and publish app and libraries
    COPY . .
    RUN dotnet publish -c release -o /app --no-restore
    
    
    # final stage/image
    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
    WORKDIR /app
    COPY --from=build /app ./
    ENTRYPOINT ["dotnet", "aspnetapp.dll"]
    
    1. 创建了以下 .dockerignore
    # directories
    **/bin/
    **/obj/
    **/out/
    
    # files
    Dockerfile*
    **/*.trx
    **/*.md
    **/*.ps1
    **/*.cmd
    **/*.sh
    
    1. docker build --pull -t test .

    构建的 Dockerfile 没有问题。您可以尝试这些步骤并报告结果吗?

    【讨论】:

      【解决方案3】:

      在阅读此链接https://github.com/dotnet/sdk/issues/3059后,我遇到了同样的问题

      我只是将/restore 附加到构建命令并且它起作用了。

      就这样

      RUN dotnet publish --no-restore -c Release -o /app --no-cache /restore
      

      现在它工作得很好。

      【讨论】:

        【解决方案4】:

        对我来说,添加--no-cache flag

        很有帮助
        RUN dotnet publish -c Release -o out --no-cache
        

        【讨论】:

          【解决方案5】:

          我有一个非常相似的问题

          error MSB4018: NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder '/usr/local/share/dotnet/sdk/NuGetFallbackFolder'.
          

          我添加了RUN mkdir -p /usr/local/share/dotnet/sdk/NuGetFallbackFolder

          然后它走得更远,但由于我认为只是随 SDK 分发的东西的库解析失败了。

          /usr/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.1 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. 
          

          我认为带有标签 3.1.201-buster、3.1-buster、3.1.201、3.1、latest 的 mcr.microsoft.com/dotnet/core/sdk:3.1 4/09/2010 Docker 映像已损坏。

          我更改为基于 Ubuntu 仿生的图像,它又可以正常工作了。

          USE mcr.microsoft.com/dotnet/core/sdk:3.1-bionic
          

          【讨论】:

          • 如果注释掉 'RUN dotnet restore' 图像将构建
          猜你喜欢
          • 1970-01-01
          • 2022-11-06
          • 1970-01-01
          • 2020-11-22
          • 2021-12-06
          • 1970-01-01
          • 1970-01-01
          • 2021-06-03
          • 1970-01-01
          相关资源
          最近更新 更多