2

I have a problem using docker and couldn't find a suitable solution.

I am trying to create a docker image using dotnet sdk 3.1

The thing is, when the docker tries to execute the build statement, it fails and the error output is

CSC: error CS5001: the program does not contain a suitable static 'main' method for an entry point

Here my Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Mail.StateMachine.csproj", "statemachine/"]
RUN dotnet restore "statemachine/Mail.StateMachine.csproj"
WORKDIR "/src/statemachine"
COPY . .statemachine
RUN dotnet build "Mail.StateMachine.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Mail.StateMachine.csproj" -c Release -o /app/publish

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

Here the Main Method

public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .CreateLogger();

            try
            {
                Log.Information("Starting web host");
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Fran
  • 31
  • 1
  • 3
  • And do you have static Main method? – Klaus Gütter Nov 05 '20 at 16:32
  • Yeah, I got it in program.cs – Fran Nov 05 '20 at 16:41
  • Have you read https://stackoverflow.com/questions/52991469/getting-program-does-not-contain-a-static-main-method-suitable-for-an-entry-p?rq=1 – Caius Jard Nov 05 '20 at 17:01
  • Does this answer your question? [Getting "Program does not contain a static 'Main' method suitable for an entry point" when building using docker, why?](https://stackoverflow.com/questions/52991469/getting-program-does-not-contain-a-static-main-method-suitable-for-an-entry-p) – Klaus Gütter Nov 06 '20 at 05:20
  • 1
    Yes but it doesn't fix the problem, I keep getting the same. – Fran Nov 06 '20 at 07:45

0 Answers0