【问题标题】:Client-side Blazor hosted in Docker fail while IL linkingDocker 中托管的客户端 Blazor 在 IL 链接时失败
【发布时间】:2020-11-23 09:26:06
【问题描述】:

我尝试从我的客户端 Blazor 应用程序构建 Docker 映像。该应用由 ASP.NET Core WebAPI 项目提供服务。

为此,我让 VS 生成适当的 Dockerfile。

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Gtv.Blazor/Server/Gtv.Blazor.Server.csproj", "Gtv.Blazor/Server/"]
COPY ["Blazor/Shared/Gtv.Blazor.Shared.csproj", "Gtv.Blazor/Shared/"]
COPY ["Gtv.Blazor/Client/Gtv.Blazor.Client.csproj", "Gtv.Blazor/Client/"]
RUN dotnet restore "Gtv.Blazor/Server/Gtv.Blazor.Server.csproj"
COPY . .
WORKDIR "/src/Gtv.Blazor/Server"
RUN dotnet build "Gtv.Blazor.Server.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Gtv.Blazor.Server.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Gtv.Blazor.Server.dll"]

构建时出现 IL 链接器错误:

Step 12/21 : RUN dotnet restore "Gtv.Blazor/Server/Gtv.Blazor.Server.csproj"
 ---> Using cache
 ---> 40fd2064543b
Step 13/21 : COPY . .
 ---> Using cache
 ---> 027a267a84ca
Step 14/21 : WORKDIR "/src/Gtv.Blazor/Server"
 ---> Using cache
 ---> 20349fa5c602
Step 15/21 : RUN dotnet build "Gtv.Blazor.Server.csproj" -c Release -o /app/build
 ---> Running in d1134f6e3d48
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 28.71 ms for /src/Gtv.Blazor/Client/Gtv.Blazor.Client.csproj.
  Restore completed in 28.69 ms for /src/Gtv.Blazor/Server/Gtv.Blazor.Server.csproj.
  Restore completed in 1.02 ms for /src/Gtv.Blazor/Shared/Gtv.Blazor.Shared.csproj.
  Gtv.Blazor.Shared -> /app/build/Gtv.Blazor.Shared.dll
  Fatal error in Mono IL Linker
/root/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.1/targets/Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj/Release/netstandard2.1/Gtv.Blazor.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [/src/Gtv.Blazor/Client/Gtv.Blazor.Client.csproj]
   ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj/Release/netstandard2.1/Gtv.Blazor.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
     at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
     at Mono.Linker.AssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
     at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
     at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
     at Mono.Linker.LinkContext.Resolve(String name)
     at Mono.Linker.Steps.ResolveFromAssemblyStep.Process()
     at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)
/root/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.1/targets/Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code 134. [/src/Gtv.Blazor/Client/Gtv.Blazor.Client.csproj]

Build FAILED.

/root/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.1/targets/Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj/Release/netstandard2.1/Gtv.Blazor.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [/src/Gtv.Blazor/Client/Gtv.Blazor.Client.csproj]
/root/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.1/targets/Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code 134. [/src/Gtv.Blazor/Client/Gtv.Blazor.Client.csproj]
    0 Warning(s)
    2 Error(s)

【问题讨论】:

    标签: docker asp.net-core blazor-client-side docker-build blazor-webassembly


    【解决方案1】:

    我遇到了和你一样的问题。删除 docker 中的所有内容后,问题已解决。

    以下 docker 命令已执行:

    powershell command: docker rm -vf $(docker ps -a -q)
    powershell command: docker rmi -f $(docker images -a -q)
    powershell command: docker system prune --all
    
    docker service restart
    
    • 第一个命令是删除所有容器,包括其卷 使用
    • 第二条命令是删除所有图片
    • 第三条命令是删除所有未使用的容器、卷、网络、映像并构建缓存

    https://docs.docker.com/engine/reference/commandline/system_prune/#extended-description

    Docker 文件:

    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
    WORKDIR /app
    EXPOSE 80
    EXPOSE 443
    
    FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
    WORKDIR /src
    COPY ["PrintmillManagement/Server/PrintmillManagement.Server.csproj", "PrintmillManagement/Server/"]
    COPY ["PrintmillManagement/Client/PrintmillManagement.Client.csproj", "PrintmillManagement/Client/"]
    COPY ["PrintmillManagement/Modules/PrintmillManagement.Modules.csproj", "PrintmillManagement/Modules/"]
    COPY ["PrintmillManagement/Infrastructure/PrintmillManagement.Infrastructure.csproj", "PrintmillManagement/Infrastructure/"]
    
    RUN dotnet restore "PrintmillManagement/Server/PrintmillManagement.Server.csproj"
    COPY . .
    WORKDIR "/src/PrintmillManagement/Server"
    RUN dotnet build "PrintmillManagement.Server.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "PrintmillManagement.Server.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "PrintmillManagement.Server.dll"]
    

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多