本文介绍了带有文件内容的 .Net 资源使 docker build 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dotnet build"构建项目没有报错,同时docker build报错如下:

"dotnet build" builds a project with no errors, and at the same time docker build gives following error:

/src/Audit.Worker/Example/Resources.resx : error MSB3103: Invalid Resx file. System.IO.DirectoryNotFoundException: Could not find a part of the path '/src/Audit.Worker/Example/data/example.yaml'. [/src/Audit.Worker/Audit.Worker.csproj]

Dockerfile

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

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["./Audit.Worker/Audit.Worker.csproj", "Audit.Worker/"]
RUN dotnet restore "Audit.Worker/Audit.Worker.csproj"
COPY . /src/
WORKDIR "/src/Audit.Worker/"
RUN dotnet build "Audit.Worker.csproj" -c Release -o /apps

FROM build AS publish
RUN dotnet publish "Audit.Worker.csproj" -c Release -o /apps

FROM base AS final
WORKDIR /apps
COPY --from=publish /apps .
ENTRYPOINT ["dotnet", "Audit.Worker.dll"]

推荐答案

最终,我找到了原因.

Visual Studio 资源工具(我假设它负责 .resx 文件内容生成)假设文件路径不区分大小写,并以小写形式生成所有文件路径(即 dataexample.yaml).同时用于构建的基础 docker 镜像基于 Linux,其中路径区分大小写.

Visual Studio resources tool (I assume it responsible for .resx file content generation) makes an assumption that file paths are case insensitive and generates all file paths in lower case (i.e. dataexample.yaml). At the same time base docker image used for the build is based on Linux where paths are case sensitive.

  <data name="Example" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>dataexample.yaml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
  </data>

底线:尽管可行的解决方案是手动编辑 .resx 文件(或在需要时使用小写),但我们决定完全避免使用资源.似乎不再有适当的支持.

Bottom line: nevertheless working solution was to manually edit .resx file (or use lowercase where it's needed), we decided to avoid using resources at all. It seems there is no proper support for it anymore.

这篇关于带有文件内容的 .Net 资源使 docker build 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:58