C# 程序不包含适合入口点的静态“Main”方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/577298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Program does not contain a static 'Main' method suitable for an entry point
提问by
Suddenly my whole project stopped compiling at all, showing the following message:
突然间,我的整个项目完全停止编译,显示以下消息:
Program 'path_to_obj_project_folder' does not contain a static 'Main' method suitable for an entry point
程序“path_to_obj_project_folder”不包含适合入口点的静态“Main”方法
I made no changes to project properties, just added some classes, moved some other classes into folders. Its an WPF Application project so it should be all OK. Entry point is where it should be, file App.xaml was not modified at all :(
我没有更改项目属性,只是添加了一些类,将其他一些类移到文件夹中。它是一个 WPF 应用程序项目,所以应该没问题。入口点是它应该在的地方,文件 App.xaml 根本没有被修改:(
What should I do to make it work again?
我该怎么做才能让它再次工作?
采纳答案by Kent Boogaart
Check the properties of App.xaml. Is the Build Action
still ApplicationDefinition
?
检查App.xaml的属性。是Build Action
还ApplicationDefinition
?
回答by Ryan Lundy
You can also run into this if you're working on a WPF project that was started in VS 2010 (Beta 1), then moved into VS 2008.
如果您正在处理在 VS 2010(Beta 1)中启动的 WPF 项目,然后移入 VS 2008,您也可能会遇到这种情况。
Under the project properties, the .NET framework version gets unset (since .NET 4.0 isn't valid in VS 2008), and for some reason that causes this error.
在项目属性下,.NET 框架版本未设置(因为 .NET 4.0 在 VS 2008 中无效),并且由于某种原因导致此错误。
If you set the .NET framework (e.g. to .NET 3.5), the error goes away.
如果您设置 .NET 框架(例如设置为 .NET 3.5),错误就会消失。
回答by Kervin Ramen
Maybe the "Output type" in properties->Application of the project must be a "Class Library" instead of console or windows application.
也许项目的属性->应用程序中的“输出类型”必须是“类库”而不是控制台或Windows应用程序。
回答by AndyA
Just in case anyone is having the same problem... I was getting this error, and it turned out to be my <Application.Resources>
in my App.xaml file. I had a resource outside my resource dictionary tags, and that caused this error.
以防万一有人遇到同样的问题......我收到了这个错误,结果是我<Application.Resources>
在我的 App.xaml 文件中。我在资源字典标签之外有一个资源,这导致了这个错误。
回答by Eugene Griaznov
In my case (after renaming application namespace manually) I had to reselect the Startup object in Project properties.
就我而言(手动重命名应用程序命名空间后),我必须在项目属性中重新选择 Startup 对象。
回答by leoneboaventura
Just in case someone is still getting the same error, even with all the help above: I had this problem, I tried all the solutions given here, and I just found out that my problem was actually another error from my error list (which was about a missing image set to be my splash screen. i just changed its path to the right one and then all started to work)
以防万一有人仍然遇到同样的错误,即使有了上面的所有帮助:我遇到了这个问题,我尝试了这里给出的所有解决方案,我才发现我的问题实际上是我的错误列表中的另一个错误(这是关于丢失的图像设置为我的启动画面。我只是将其路径更改为正确的路径,然后一切都开始工作)
回答by Arun Pandey
I have got the same error but then I found out that I typed small m instead of capital M in Main method
我遇到了同样的错误,但后来我发现我在 Main 方法中输入了 small m 而不是大写 M
回答by pixparker
Project Properties \ Output file -> Select Class Library :)
项目属性 \ 输出文件 -> 选择类库 :)
回答by Faraz Ahmed Qureshi
As what, I guess pixparker wanted to say, but remained to be not clear enough, for me at least, do ensure that... All "Other Projects"have an "Output Type"of "Class Library"selected while... Only "One Project"being selected as either "Window Application"or "Console Application"output.
至于什么,我猜 pixparker 想说,但仍然不够清楚,至少对我来说,确保......所有“其他项目”都选择了“类库”的“输出类型”,同时...... 只有“一个项目”被选为“窗口应用程序”或“控制台应用程序”输出。