简体   繁体   English

Visual Studio:当链接文件在项目中时,docker 构建失败

[英]Visual Studio: docker build fails when linked files are in the project

I have a .NET 6 Console project that includes 2 binaries as linked files:我有一个 .NET 6 控制台项目,其中包括 2 个二进制文件作为链接文件:

 <ItemGroup>
    <None Include="..\HFMath\bin\HFMath.dll" Link="HFMath.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="..\HFMath\bin\libHFMath.so" Link="libHFMath.so">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

I need to deploy it as a docker container.我需要将它部署为 docker 容器。 The Dockerfile scaffolded by Visual Studio is Visual Studio 搭建的 Dockerfile 是

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ConsoleApp1/ConsoleApp1.csproj", "ConsoleApp1/"]
RUN dotnet restore "ConsoleApp1/ConsoleApp1.csproj"
COPY . .
WORKDIR "/src/ConsoleApp1"
RUN dotnet build "ConsoleApp1.csproj" -c Release -o /app/build

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

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

when I run docker build, I get the following error:当我运行 docker 构建时,我收到以下错误:

#15 1.054   Determining projects to restore...
#15 1.322   All projects are up-to-date for restore.
#15 2.552 /usr/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "/src/HFMath/bin/libHFMath.so" because it was not found. [/src/ConsoleApp1/ConsoleApp1.csproj]
#15 2.552 /usr/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "/src/HFMath/bin/HFMath.dll" because it was not found. [/src/ConsoleApp1/ConsoleApp1.csproj]
#15 2.556
#15 2.556 Build FAILED.

I know that docker doesn't support symlinks, but I still need to build the image.我知道 docker 不支持符号链接,但我仍然需要构建图像。 How do I fix this (without changing the .NET project)?我该如何解决这个问题(不更改 .NET 项目)?

Problem问题

If you have auto generated the Dockerfile using Visual Studio, it will also have created a .dockerignore file (usually in the .sln folder).如果您使用 Visual Studio 自动生成Dockerfile ,它还将创建一个.dockerignore文件(通常在.sln文件夹中)。 That file will contain an entry to exclude **/bin from the build context.该文件将包含一个从构建上下文中排除**/bin的条目。

This means when the COPY. .这意味着当COPY. . COPY. . executes, it is ignoring the files in any bin folder执行时,它会忽略任何bin文件夹中的文件

Solution解决方案

  1. Find and edit the .dockerignore file.查找并编辑.dockerignore文件。
  2. Add the line !HFMath/bin/ - this will tell Docker to NOT ignore the HFMath/bin folder添加行!HFMath/bin/ - 这将告诉 Docker 不要忽略HFMath/bin文件夹
  3. Run your docker build command again再次运行您的docker build命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Docker中构建Visual Studio C ++项目 - Build Visual Studio C++ project in docker 由于缺少属性文件,MSBuild 无法构建 Visual Studio 项目(可能与 IDE 相关) - MSBuild fails to build Visual Studio Project due to missing property files (potentially IDE related) docker 支持 Visual Studio 项目中的“未找到 Docker 构建路径” - “Docker build path not found” in docker support Visual Studio Project Visual Studio Team Service失败了Task Docker Build - Visual Studio Team Service fails Task Docker Build Docker无法在Visual Studio 2017上构建-未经授权:需要身份验证 - Docker fails to build on visual studio 2017 - unauthorized: authentication required 添加项目引用和 nuget 提要时,Docker 构建失败 - Docker build fails when project reference and nuget feed added 在 Visual Studio 2017 中打开解决方案时无法构建 Docker 映像 - Docker image unable to build when solution is open in Visual Studio 2017 在 Visual Studio 中使用相同的 docker 文件构建 docker 映像的 Azure Pipeline 失败 - Azure Pipeline to build docker images fails using same docker file in Visual Studio 在RabbitMQ容器的Visual Studio项目中运行Docker Compose时出错 - Error when running Docker Compose in Visual Studio project for RabbitMQ container 码头支持视觉工作室2017年失败 - docker support visual studio 2017 fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM