MSBuild 错误 - 程序不包含适合入口点的静态 'Main' 方法

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

我有一个 visual studio 解决方案,其中包含一些 class 库项目和一个 windows 服务项目。

我正在尝试使用以下 msbuild 命令构建它:

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

但是,我收到以下错误:

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

它试图以某种方式在 class 库项目中找到入口点,而不是使用 windows 服务项目。

我相信如果我尝试构建 WindowsService.csproj 而不是 .sln 文件,那么它可能会解决问题。但是,WindowsService.CsProj 不包含所有其他 dll 引用,因此我必须构建 .sln 文件。

有没有其他方法可以修复此错误?

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?

由于您只是使用 msbuild 命令行构建了整个解决方案,因此意味着您的命令行参数适用于解决方案中的所有项目。

正如您的描述,您的解决方案中有一些 class 库项目不包含静态 Main 方法,因此无法指定作为 Windows 应用程序

VS 中的项目具有三种输出类型:Console ApplicationWindows Application 包含静态 Main 函数,而 Class Library Application 不包含它。

结论

如果您使用命令行构建整个解决方案,您应该确保命令行中的所有参数都适用于所有项目。

构建单个项目时 Windows Service project,只需确保当前项目具有静态 main 函数并且它确实具有。

解决方案

1)由于你的解决方案只包含一个winexe项目和其他class库项目,请在命令行中删除OutputType=Winexe .

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

希望对您有所帮助。