Search code examples
.netdocker.net-coreresx

.Net resource with files content make docker build fail


"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"]

Solution

  • 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.