具有文件内容的 .Net 资源使 docker 构建失败
.Net resource with files content make docker build fail
"dotnet build" 构建一个没有错误的项目,同时 docker 构建出现以下错误:
/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]
Docker 文件
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 文件内容)假设文件路径不区分大小写,并以小写形式生成所有文件路径(即 data\example.yaml).同时,用于构建的基础 docker 图像基于 Linux,其中路径区分大小写。
<data name="Example" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>data\example.yaml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
底线:尽管如此,可行的解决方案是手动编辑 .resx 文件(或在需要时使用小写字母),我们决定完全避免使用资源。好像没有合适的支持了。
我发现的解决方案是您必须通过“添加资源”->“添加现有文件”来添加文件。在此之后,我在构建容器时不再收到此错误。
"dotnet build" 构建一个没有错误的项目,同时 docker 构建出现以下错误:
/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]
Docker 文件
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 文件内容)假设文件路径不区分大小写,并以小写形式生成所有文件路径(即 data\example.yaml).同时,用于构建的基础 docker 图像基于 Linux,其中路径区分大小写。
<data name="Example" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>data\example.yaml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
底线:尽管如此,可行的解决方案是手动编辑 .resx 文件(或在需要时使用小写字母),我们决定完全避免使用资源。好像没有合适的支持了。
我发现的解决方案是您必须通过“添加资源”->“添加现有文件”来添加文件。在此之后,我在构建容器时不再收到此错误。