2

I'm trying to containerize an ASP.NET hosted Blazor WebAssembly project, but I can't build my image. It fails on dotnet build:

error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/Web/VL.Challenge.Blazor.Client/VL.Challenge.Blazor.Client.csproj]

Folder structure

build
--API
----Dockerfile
src
--Web
----VL.Challenge.API
----VL.Challenge.Blazor.Client
...
docker-compose.yaml

Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_ENVIRONMENT Production
ENV ASPNETCORE_URLS=http://+:80

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build

WORKDIR /src
COPY /src/Web/VL.Challenge.API/VL.Challenge.API.csproj                     Web/VL.Challenge.API/
COPY /src/Web/VL.Challenge.Blazor.Client/VL.Challenge.Blazor.Client.csproj Web/VL.Challenge.Blazor.Client/
COPY /src/VL.Challenge.Common/VL.Challenge.Common.csproj                   VL.Challenge.Common/
COPY /src/VL.Challenge.Domain/VL.Challenge.Domain.csproj                   VL.Challenge.Domain/
COPY /src/VL.Challenge.Storage/VL.Challenge.Storage.csproj                 VL.Challenge.Storage/

WORKDIR /src/Web/VL.Challenge.API
RUN dotnet restore VL.Challenge.API.csproj

WORKDIR /src/
COPY src/Web/VL.Challenge.API           Web/
COPY src/Web/VL.Challenge.Blazor.Client Web/
COPY src/VL.Challenge.Common            .
COPY src/VL.Challenge.Domain            .
COPY src/VL.Challenge.Storage           .

WORKDIR /src/Web
RUN dotnet build VL.Challenge.API/VL.Challenge.API.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish VL.Challenge.API.csproj -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final

WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT dotnet VL.Challenge.API.dll

This setup works if I remove the dependency of VL.Challenge.API to VL.Challenge.Blazor.Client so I know my docker-compose.yaml sets the correct context for the image. Tried with both root-level and Program class options. The project builds locally without issues.

Am I missing something obvious here?

1 Answer 1

1

Your COPY statements should maintain the structure from the host.

These COPY statements copy files to different directories. You get your error because VL.Challenge.API is copied to Web. It should be copied to Web/VL.Challenge.API.

WORKDIR /src/
COPY src/Web/VL.Challenge.API           Web/
COPY src/Web/VL.Challenge.Blazor.Client Web/
COPY src/VL.Challenge.Common            .
COPY src/VL.Challenge.Domain            .
COPY src/VL.Challenge.Storage           .

The easiest way to copy your source is to do it in one go and replace those statements with

WORKDIR /src/
COPY src .

which will copy all the source in one go and maintain the directory structure.

Sign up to request clarification or add additional context in comments.

3 Comments

I just tried that, same error. While I agree that COPY src//* . is better than my approach, I don't think you are correct regarding VL.Challenge.API/ contents being copied directly to Web/. I think that would be the case if it was COPY src/Web/VL.Challenge.API/*, which targets all files in the directory. I would expect my statement to copy the whole directory. And indeed that's what it does under linux, using cp. Not sure how I can verify this within the container though.
It seems the Docker COPY behaves differently than cp. I pulled an SQL image to keep my container running so I can inspect it's directory structure. COPY src/* . also produces a mess of files within a single directory. In the end I had to specify all projects like COPY src/Web/VL.Challenge.API VL.Challenge.API. If you update your answer with this info, I'll mark it as accepted.
Sorry about that. COPY src . should copy it all and preserve the directory structure. I've updated the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.