I have an ASP.NET CORE app with a few projects inside and the following Dockerfile:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY src/Mbv.Vans.Core/Mbv.Vans.Core.csproj Mbv.Vans.Core/
COPY src/Mbv.Vans.Common/Mbv.Vans.Common.csproj Mbv.Vans.Common/
COPY src/Mbv.Vans.Api/Mbv.Vans.Api.csproj Mbv.Vans.Api/
RUN dotnet restore Mbv.Vans.Api/Mbv.Vans.Api.csproj
COPY . .
FROM build AS publish
RUN dotnet publish Mbv.Vans.Api/Mbv.Vans.Api.csproj --no-restore -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Mbv.Vans.Api.dll"]
On line RUN dotnet publish Mbv.Vans.Api/Mbv.Vans.Api.csproj --no-restore -c Release -o /app
When it tries to build the project, it fails with error:
"Program does not contain a static 'Main' method suitable for an entry point"
Here is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
I searched a lot of questions regarding this issue and divide it into the following resolutions:
COPY . .
is not fixing this issue- I have only one
static void main
<GenereteProgramFile> false
doesn't help.
Could someone can help me to beat this awfull issue?
So, I ran across this same issue and drove me insane. The solution here is to skip the build and go right to a publish.
I was helped by looking at this particular sample: https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile.alpine-x64
As you can see in there, there is no build occurring. There is a restore, and then a publish. Why no build? I don't know. I'm investigating, but I'm happy it worked for me at least. Let me know how it goes.
Edited for additional info:
Here is the original non-working Dockerfile:
...and here the the newly working Dockerfile:
As you can see, what I generally did was remove the line:
...as well as do some clean-up.
The general take-away is that running the build command on my dev machine(s) will work fine, but as part of building the container, it will fail.