# ── Build stage ────────────────────────────────────────
# Uses the .NET 8 SDK to restore and compile your project.
# Change "MyCobaltApp.csproj" to match your own .csproj filename.
FROM mcr.microsoft.com/dotnet/sdk:8.0-windowsservercore-ltsc2022 AS build
WORKDIR /src
COPY MyCobaltApp.csproj ./
RUN dotnet restore
COPY . .
# IMPORTANT: do NOT add --self-contained here.
RUN dotnet publish -c Release --no-restore -o /app/publish

# ── Grab ASP.NET runtime binaries ────────────────────
FROM mcr.microsoft.com/dotnet/aspnet:8.0-windowsservercore-ltsc2022 AS aspnet

# ── Runtime stage ─────────────────────────────────────
# Uses the FULL Windows Server image (not Server Core) because
# headless Chromium requires Media Foundation and other DLLs
# that Microsoft removed from Server Core.
FROM mcr.microsoft.com/windows/server:ltsc2022 AS runtime

# Copy the ASP.NET runtime from the official image.
COPY --from=aspnet ["C:/Program Files/dotnet", "C:/Program Files/dotnet"]
RUN setx /M PATH "C:\Program Files\dotnet;%PATH%"
ENV DOTNET_RUNNING_IN_CONTAINER=true
ENV ASPNETCORE_HTTP_PORTS=8080

# Chromium requires the Visual C++ Redistributable.
ADD https://aka.ms/vs/17/release/vc_redist.x64.exe /temp/vc_redist.x64.exe
RUN C:\temp\vc_redist.x64.exe /install /quiet /norestart
RUN del C:\temp\vc_redist.x64.exe

WORKDIR /app
COPY --from=build /app/publish .
# Change "MyCobaltApp.dll" to match your own project name.
ENTRYPOINT ["dotnet", "MyCobaltApp.dll"]
