developer
developer

Reputation: 1673

MSBuild error - Program does not contain a static 'Main' method suitable for an entry point

I have a visual studio solution containing some class library projects and a windows service project.

I am trying to build it using the following msbuild command:

MSBuild SolutionName.sln /t:rebuild /p:Configuration=Release;OutputType=Winexe /clp:ErrorsOnly

However, I am getting the following error:

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [C:..\BusinessObjects.csproj]

Somehow it tries to find an entry point inside a class library project instead of using the windows service project.

I believe if I try to build WindowsService.csproj instead of .sln file then it may fix the issue. However, WindowsService.CsProj does not contain all other dll references so I have to build .sln file.

Is there any other way I can fix this error?

Upvotes: 0

Views: 627

Answers (1)

Mr Qian
Mr Qian

Reputation: 23740

I believe if I try to build WindowsService.csproj instead of .sln file then it may fix the issue. However, WindowsService.CsProj does not contain all other dll references so I have to build .sln file.

Is there any other way I can fix this error?

Since your just build the whole solution with msbuild command line , it means that the parameters from your command line apply to all projects in the solution.

As your description, you have some class library projects in your solution which does not contains a static Main method, So it cannot be specified as a Windows application.

Projects in VS have three output types: Console Application and Windows Application contains a static Main function while Class Library Application does not contain it.

Conclusion

If you build a whole solution with the command line, you should make sure that all the parameters from the command line apply to all projects.

When you build a single project Windows Service project, just make sure the current project has a static main function and it actually has.

Solution

1) Since your solution contains only one winexe project and other class library projects, please delete OutputType=Winexe in the command line.

MSBuild SolutionName.sln /t:rebuild /p:Configuration=Release /clp:ErrorsOnly

Hope it could help you.

Upvotes: 1

Related Questions