.Net resource with files content make docker build fail
Asked Answered
C

2

6

"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"]
Cooperage answered 1/4, 2020 at 14:34 Comment(0)
C
12

Eventually, I figured out what was the reason.

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. data\example.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>data\example.yaml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
  </data>

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.

Cooperage answered 1/4, 2020 at 14:34 Comment(2)
what do you mean there is no proper support for it?Riccardo
They're probably referring to Microsoft's attitude to this bug: developercommunity.visualstudio.com/t/…Mesozoic
C
2

What I found as solution is that you have to add file through the "Add Resource" -> "Add Existing File". After this I stopped getting this error when building my container.

Commonplace answered 22/12, 2021 at 21:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.