【问题标题】:program doesn't contain a static 'main' method suitable for an entry point程序不包含适合入口点的静态“主”方法
【发布时间】:2014-12-13 23:56:22
【问题描述】:

我知道有很多关于这个问题的问题,但我的问题是最糟糕的。 我有一个包含很多 WPF 应用程序的大项目。我错误地删除了App.xaml,现在我在构建中有错误。我尝试的是备份App.xaml,即使我再次将它放在我的项目中,我仍然得到这个错误。 该怎么办 ?谢谢。

【问题讨论】:

  • 从备份恢复后是否重新编译?备份有效吗?它是包含在项目中还是只是目录中的一个文件?基本上,在错误消息之后,是否存在应用程序中的static Main 方法? (旁注:撤消代码中的重大更改的一种有效方法是从源代码控制恢复到已知的工作版本。)

标签: c# wpf xaml


【解决方案1】:

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

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

/// <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();
}

【讨论】:

  • @RonYamin 如果这个答案确实回答了你的问题,你应该accept it
猜你喜欢
  • 2012-04-21
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
  • 1970-01-01
  • 1970-01-01
  • 2013-06-10
  • 1970-01-01
相关资源
最近更新 更多