Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Program does not contain a static 'Main' method suitable for an entry point #401

Closed
xiaotupansy opened this issue Mar 28, 2018 · 12 comments
Closed
Labels
closed-external Closed because the issue is external to the project in this repo.

Comments

@xiaotupansy
Copy link

xiaotupansy commented Mar 28, 2018

Hi,
Environment :
Centos 7.3
Docker version 17.09.0-ce, build afdb6d4
microsoft/aspnetcore-build docker image, pulled just now using docker pull microsoft/aspnetcore-build

I have two projects in solution.

demo.csproj default asp.net mvc project set up by vs 2017 community
Library.csproj default library project set up by vs 2017 community

Demo project reference the Library project.

Here is my dockerfile:


FROM microsoft/aspnetcore-build AS builder
WORKDIR /sln
COPY ./demo.sln  ./
COPY ./demo/demo.csproj  ./demo/demo.csproj
COPY ./Library/Library.csproj  ./Library/Library.csproj

RUN dotnet restore
RUN dotnet build -c Release --no-restore

RUN dotnet publish "./demo/demo.csproj" -c Release -o "../dist" --no-restore

FROM microsoft/aspnetcore
WORKDIR /app
COPY --from=builder /sln/dist .
ENTRYPOINT ["dotnet", "demo.dll"]


Here is my docker command:

docker build /site/test -t aspnetapp

Here is the output:

[root@worth ~]# docker build /site/test -t aspnetapp
Sending build context to Docker daemon  5.083MB
Step 1/12 : FROM microsoft/aspnetcore-build AS builder
 ---> 244f6193d21a
Step 2/12 : WORKDIR /sln
 ---> Using cache
 ---> 44b558ba58b0
Step 3/12 : COPY ./demo.sln ./
 ---> 7dfd84d431b9
Step 4/12 : COPY ./demo/demo.csproj ./demo/demo.csproj
 ---> e8e751c2bca7
Step 5/12 : COPY ./Library/Library.csproj ./Library/Library.csproj
 ---> b0a979746fdf
Step 6/12 : RUN dotnet restore
 ---> Running in 5dabe8ff613f
  Restoring packages for /sln/Library/Library.csproj...
  Restoring packages for /sln/demo/demo.csproj...
  Generating MSBuild file /sln/Library/obj/Library.csproj.nuget.g.props.
  Generating MSBuild file /sln/Library/obj/Library.csproj.nuget.g.targets.
  Restore completed in 718.77 ms for /sln/Library/Library.csproj.
  Restoring packages for /sln/demo/demo.csproj...
  Restore completed in 3.46 sec for /sln/demo/demo.csproj.
  Generating MSBuild file /sln/demo/obj/demo.csproj.nuget.g.props.
  Generating MSBuild file /sln/demo/obj/demo.csproj.nuget.g.targets.
  Restore completed in 5.91 sec for /sln/demo/demo.csproj.
 ---> 75c5eb8d871e
Removing intermediate container 5dabe8ff613f
Step 7/12 : RUN dotnet build -c Release --no-restore
 ---> Running in 40ee491a3603
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Library -> /sln/Library/bin/Release/netcoreapp2.0/Library.dll
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/sln/demo/demo.csproj]

Build FAILED.

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/sln/demo/demo.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:06.10
The command '/bin/sh -c dotnet build -c Release --no-restore' returned a non-zero code: 1
@natemcmaster
Copy link
Contributor

This error isn't specific to Docker. It's a C# compiler error. For any project that is <OutputType>exe</OutputType>, you need to have a method like this public static void Main(string[] args) somewhere in your project.

@natemcmaster natemcmaster added the closed-external Closed because the issue is external to the project in this repo. label Mar 29, 2018
@xiaotupansy
Copy link
Author

xiaotupansy commented Mar 30, 2018

Here is the output from centos without docker using the same code:

[root@localhost ~]# dotnet build -c release /site/test1/demo/demo.sln
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Library -> /site/test1/demo/Library/bin/Release/netcoreapp2.0/Library.dll
  demo -> /site/test1/demo/demo/bin/Release/netcoreapp2.0/demo.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:25.02
[root@localhost ~]#

So I think maybe something wrong in build image.

I did a lot of searching before I post this issue. I'm sure code can work both in iisexpress and kestrel.

@natemcmaster
Copy link
Contributor

If you can provide exact steps to reproduce the issue, we may be able to investigate more. The error message indicates that you are missing some of your source code when building inside the container. Double check your COPY statements in your Dockerfile. Not trying to be mean -- we just don't have enough info to investigate, so I closed it because we are not planning on taking action here.

@natemcmaster
Copy link
Contributor

...and of course, I see you edited the original issue. So far you've only copied your .csproj files into the container. You need the .cs files too. Add this line to your dockerfile before dotnet build to copy everything.

COPY . .

@xiaotupansy
Copy link
Author

xiaotupansy commented Mar 30, 2018

Thanks.
After copy files, it works now.

@lcr0815
Copy link

lcr0815 commented May 13, 2018

what is the exact meaning of COPY . .

@natemcmaster
Copy link
Contributor

Syntax for this directive is COPY <src> <dest>. This is the same as COPY ./ ./. See https://docs.docker.com/engine/reference/builder/#copy

@Rickinio
Copy link

Rickinio commented Jan 22, 2019

Hi, i had the exact same error message and for me the issue was that i had my Docker file at the same level as my .csproj. When i moved csproj one level deeper, docker build run successfully.

@lawphotog
Copy link

Got the same issue and what Rickinio said was right. Once I moved the Docker file one level up, things look better. But why was the file at the same level from the first place. I just created a fresh app. I guess they had to put at the same level so that Dockerfile is included in the solution explorer for those who use Visual Studio. VS seems smart enough to find things and start docker but docker build command wasn't working unless i moved the Dockerfile.

lloydsmithjr03 added a commit to lloydsmithjr03/aks_test that referenced this issue Jan 26, 2019
Moving the Dockerfile up a level from the csproj corrected the issue
of the Docker build failing due to not finding a Main entry
aspnet/aspnet-docker#401 (comment)
@Teklie
Copy link

Teklie commented Mar 20, 2019

This error isn't specific to Docker. It's a C# compiler error. For any project that is <OutputType>exe</OutputType>, you need to have a method like this public static void Main(string[] args) somewhere in your project.

Thanks. It worked.

@davidebbo
Copy link

I ran into the same thing. There seems to be a VS bug here causing it to create the Dockerfile in the wrong place.

@cilliemalan
Copy link

I randomly got this issue when I was (accidentally) building to a parent directory. Like so:

WORKDIR /app/src/
RUN dotnet build Thing.csproj -c Release -o /app

Fixed it by chainging /app to /out

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-external Closed because the issue is external to the project in this repo.
Projects
None yet
Development

No branches or pull requests

8 participants