Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Program does not contain a static 'Main' method suitable for an entry point" when building using docker, why?

Tags:

I'm running into an issue using Docker and couldn't find a proper solution.

I'm trying to build a Docker image using .NET SDK 2.1.

The thing is that when Docker tries to run the build statement, it fails and the error output is

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point

The funny thing is that if I perform the build statement on command line locally, it works fine.

I have already checked my LanguageVersion tag on the project and it is 7.3.

Here is my Docker file

FROM microsoft/dotnet:2.1-sdk AS builder   WORKDIR /src COPY ./nuget  ./nuget COPY ./NuGet.Config ./ COPY Services/AadTracking ./  # Copy all the referenced projects  COPY ./Services/AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj ./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj COPY ./Services/AadTracking/Office.Re.Service.AadTracking/Office.Re.Service.AadTracking.csproj ./AadTracking/Office.Re.Service.AadTracking/Office.Re.Service.AadTracking.csproj COPY ./Services/AadTracking/Company/Office.Re.Service.AadTracking.Company/Office.Re.Service.AadTracking.Company.csproj ./AadTracking/Company/Office.Re.Service.AadTracking.Company/Office.Re.Service.AadTracking.Company.csproj COPY ./Services/AadTracking/Office.Re.Service.AadTracking.EventStore/Office.Re.Service.AadTracking.EventStore.csproj ./AadTracking/Office.Re.Service.AadTracking.EventStore/Office.Re.Service.AadTracking.EventStore.csproj  # Restore packages RUN dotnet restore "./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj"  RUN dotnet build -c Debug --no-restore "./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj"  # COPY source code  #aad tracking COPY ./Services/AadTracking/Company/Company.Service.AadTracking ./AadTracking/Company/Company.Service.AadTracking/ COPY ./Services/AadTracking/Office.Re.Service.AadTracking ./AadTracking/Office.Re.Service.AadTracking/ COPY ./Services/AadTracking/Company/Office.Re.Service.AadTracking.Company ./AadTracking/Company/Office.Re.Service.AadTracking.Company/ COPY ./Services/AadTracking/Office.Re.Service.AadTracking.EventStore ./AadTracking/Office.Re.Service.AadTracking.EventStore/  # Publish RUN dotnet publish "./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj" -c Debug -o "../../dist"  # #Build the app image FROM microsoft/dotnet:2.1-aspnetcore-runtime   WORKDIR /app    ENV ASPNETCORE_ENVIRONMENT Switch ENV REINSURANCE_INSTANCE Docker-dev   COPY --from=builder /dist .    ENTRYPOINT ["dotnet", "Company.Service.AadTracking.dll"] 

Thanks for your help!

like image 855
Leo Ferreira Avatar asked Oct 25 '18 14:10

Leo Ferreira


1 Answers

I know this is little bit late to answer. Still VS 2019 has the same issue with .NET Core 3.1. I took a peek at the examples provided by Microsoft. Turns out the Docker file resided in a different place in the solution and Docker copy command wasn't working properly.

You have to move your docker file one directory up, so that they are at the same level as the sln file. It will fix the issue.

OR else you can change the paths like below sample docker file WITHOUT changing the docker file location, IMHO it is better to keep the docker file with other files.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim-arm64v8 AS base WORKDIR /app EXPOSE 80 EXPOSE 443  FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src COPY ["WhatzThat.Web.csproj", "WhatzThat.Web/"] RUN dotnet restore "WhatzThat.Web/WhatzThat.Web.csproj" -r linux-arm64  WORKDIR "/src/WhatzThat.Web" COPY . .  RUN dotnet build "WhatzThat.Web.csproj" -c Release -o /app/build  FROM build AS publish RUN dotnet publish "WhatzThat.Web.csproj" -c Release -o /app/publish -r linux-arm64 --self-contained false --no-restore  FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "WhatzThat.Web.dll"] 
like image 63
marvelTracker Avatar answered Sep 18 '22 19:09

marvelTracker