【发布时间】:2017-01-17 23:58:49
【问题描述】:
我目前正在开发一项服务,但它无法构建解决方案。我有这个主要功能的代码:
[STAThread]
static void Main(string[] args)
{
ServiceBase.Run(new Service1());
}
当我评论整个事情时,构建成功。我还单独注释掉了 STAThread 和 serviceBase...,但它仍然失败,所以问题是 static void Main。我需要它来运行我的服务,所以我不能忽略它。
输出类型现在设置为 Windows 应用程序。当我将其更改为 Class Library 时,构建成功,但这会创建 .dll 文件并且我的应用程序需要是 .exe 文件。
为什么会失败?
这是 Build 的输出:
1>------ Build started: Project: Myst Service, Configuration: Debug Any CPU ------
1>C:\Users\Username\Documents\Visual Studio 2015\Projects\Myst Service\Myst Service\Service1.cs(23,21,23,25): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我搜索了 Main 的整个解决方案,似乎 Program.cs 中也有一个静态 void Main。这很常见吗?
【问题讨论】:
-
当构建失败时,您会收到错误消息,您需要在问题中包含错误消息作为编辑。
-
@ScottChamberlain 我在哪里可以找到错误消息?我没有弹出窗口,在左下角*它说构建失败,这就是我知道它失败的原因......
-
转到菜单栏中的
View,您应该会看到一个可以打开的窗口的Error List选项。 i.stack.imgur.com/yL2qc.png -
@ScottChamberlain 那里没有错误,正如我在评论那段代码时所说的那样,它确实有效,并且您可以看到该代码中没有错误,所以是的......我要去试着把它放在一个新的项目中,这个也很新鲜,但我们会看到
-
您应该将其构建为控制台应用程序。这就是 Main 入口点的用途。