程序不包含适用于入口点的静态"主"方法

Ron*_*min 3 c# wpf xaml

我知道对这个问题有很多疑问,但我的问题最糟糕.我有一个包含很多WPF应用程序的大项目.错误的是我已经删除了App.xaml,现在我在构建中有错误.我尝试的是采取备份App.xaml,甚至当我再次将它放在我的项目中时,我仍然遇到此错误.该怎么办 ?谢谢.

Luc*_*ski 13

在文件属性中,将Build Action设置为ApplicationDefinition:

文件属性

这将Main在中间输出文件(obj/App.g.cs)中为您生成一个方法:

/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public static void Main() {
    YourAppName.App app = new YourAppName.App();
    app.InitializeComponent();
    app.Run();
}
Run Code Online (Sandbox Code Playgroud)

  • @RonYamin如果这个答案实际上回答了你的问题,你应该[接受](http://meta.stackexchange.com/a/5235/130186). (2认同)