Skip to content

Commit 4f1dcb2

Browse files
committed
fix: resolve dotnet publish --no-restore issues with multi-architecture builds
- Add BUILDPLATFORM and TARGETARCH support to Dockerfile - Use architecture-specific restore and publish commands - Remove problematic --no-restore flag to prevent NuGet resolution errors - Supports both ARM64 and x86_64 builds - Resolves build issues reported in PayrollEngine/PayrollEngine#2
1 parent c7aad14 commit 4f1dcb2

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Dockerfile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
1+
# Build stage with multi-platform support
2+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build
3+
ARG TARGETARCH
4+
ARG BUILDPLATFORM
25
WORKDIR /src
36

47
# copy solution and project files
@@ -12,15 +15,26 @@ COPY ["ViewModel/PayrollEngine.WebApp.ViewModel.csproj", "ViewModel/"]
1215
# copy Directory.Build.props
1316
COPY ["Directory.Build.props", "./"]
1417

15-
RUN dotnet restore "PayrollEngine.WebApp.sln"
18+
# Restore with architecture-specific runtime
19+
RUN if [ "$TARGETARCH" = "arm64" ]; then \
20+
dotnet restore "PayrollEngine.WebApp.sln" --runtime linux-arm64; \
21+
else \
22+
dotnet restore "PayrollEngine.WebApp.sln" --runtime linux-x64; \
23+
fi
1624

1725
# copy everything else
1826
COPY . .
1927
WORKDIR "/src/Server"
20-
RUN dotnet publish "PayrollEngine.WebApp.Server.csproj" -c Release -o /app/publish --no-restore
28+
29+
# Publish with architecture-specific runtime and restore included
30+
RUN if [ "$TARGETARCH" = "arm64" ]; then \
31+
dotnet publish "PayrollEngine.WebApp.Server.csproj" -c Release -o /app/publish --runtime linux-arm64 --self-contained false; \
32+
else \
33+
dotnet publish "PayrollEngine.WebApp.Server.csproj" -c Release -o /app/publish --runtime linux-x64 --self-contained false; \
34+
fi
2135

2236
# final stage
2337
FROM mcr.microsoft.com/dotnet/aspnet:9.0
2438
WORKDIR /app
2539
COPY --from=build /app/publish .
26-
ENTRYPOINT ["dotnet", "PayrollEngine.WebApp.Server.dll"]
40+
ENTRYPOINT ["dotnet", "PayrollEngine.WebApp.Server.dll"]

0 commit comments

Comments
 (0)