Search code examples
c#dockerasp.net-coredockerfile.net-6.0

Unable to build Docker image for Arm32v7 with external assembly


I have an aspnet application which is using an external Assembly (from another project of mine).

I have added this as a project reference, and I can build and run my application locally fine, with no errors or problems. But when trying to build this for Docker with Arm32v7 (Raspberry Pi) I get the error:

warning MSB3245: Could not resolve this reference. Could not locate the assembly "SAM Shared". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

My docker file

#Below is changed to use the appropiate image for Rpi, arm32v7
FROM mcr.microsoft.com/dotnet/aspnet:6.0.1-bullseye-slim-arm32v7 AS base 
WORKDIR /app
EXPOSE 80

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

FROM build AS publish
RUN dotnet publish "HomeMonitor.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

Solution

  • This drove my crazy for ages, and stopped me progressing with my project.

    I didn't really find a solution, but more of a workaround, or actually 2!

    First workaround

    Initially as my external Assembly was relatively small and stable, then I simply created a copy and added it as a new project in this solution. I could then add it as a reference

    This worked, and I could compile and run my image on docker. But was not really a solution.

    Second workaround

    This is probably closer to a full solution, but doesn't really fix the original problem so much as avoid it so hence I still consider it a bit of a workaround and it might not suit everybody.

    I went back to my external assembly and I packaged it as a nuget package. I then uploaded it to a private package on Github. This was actually much easier than I realised (never done it before) and I found this good video to guide me https://www.youtube.com/watch?v=SiPkYrqJsps

    Then I could add it as a nuget package in my project. And this then worked perfectly, and I had no more issues.