无法为Windows或Linux加载DLL Docker

时间:2019-01-04 21:21:14

标签: docker asp.net-core .net-core windows-container

运行dotnetCore 2.2 我的.Logic库中有一个clr.dll依赖项。这个clr.dll调用了unmanaged.dll,我无法将其作为依赖项加载,而只能复制像这样的bin。     

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\myApp.Models\myApp.Models.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="CLR">
      <HintPath>..\Dependencies\NonNuget\CLR.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup>
    <None Update="unmanaged.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

我的docker文件如下所示:

   #Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.2-sdk-nanoserver-1803 AS build
WORKDIR /src
COPY ["myApp.Api/myApp.Api.csproj", "myApp.Api/"]
COPY ["myApp.logic/myApp.logic.csproj", "myApp.logic/"]
COPY ["myApp.Models/myApp.Models.csproj", "myApp.Models/"]
RUN dotnet restore "myApp.Api/myApp.Api.csproj"
COPY . .
WORKDIR "/src/myApp.Api"
RUN dotnet build "myApp.Api.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "myApp.Api.csproj" -c Release -o /app

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

**当我在docker外部运行api时,它工作正常。 **

当我创建docker映像并运行api时,我会得到

System.DllNotFoundException:无法加载DLL'unmanaged.dll'

我认为该文件未以某种方式包含在我的docker映像中,但是当我运行docker exec -it myapp时,我可以看到该文件存在

         146 appsettings.Development.json
         105 appsettings.json
    **3,426,680 unmanaged.dll**
     239,429 myApp.Api.deps.json
      13,824 myApp.Api.dll
       2,696 myApp.Api.pdb
         252 myApp.Api.runtimeconfig.dev.json
         224 myApp.Api.runtimeconfig.json
       1,188 myApp.logic.deps.json
       5,120 myApp.logic.dll
         632 myApp.logic.pdb
       1,459 myApp.Models.deps.json
       4,608 myApp.Models.dll
         708 myApp.Models.pdb
       **5,120 clr.dll**

我真的可以使用一些建议,因为我是Docker的新手,而且不确定从何而来。

0 个答案:

没有答案