我的MS Visual C#程序正在编译并运行得很好.我关闭了MS Visual C#,以便在生活中做其他事情.
我重新打开它(在做任何其他事情之前)去"发布"我的程序并得到以下错误消息:
程序C:\ myprogram.exe不包含适用于入口点的静态"Main"方法
咦?是的它确实......而且它们都提前15分钟工作了.当然,我可以相信,在我关闭之前,我不小心碰到了什么或做了什么......但是什么?我该如何解决这个问题?
我的Program.cs文件如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
namespace SimpleAIMLEditor
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainSAEForm());
}
}
}
Run Code Online (Sandbox Code Playgroud)
......那里有一些评论.没有其他错误.
救命?
Qui*_*ome 50
文件中的属性是否设置为Compile?
Bas*_*ANI 29
我正在努力解决这个错误只是因为我的一个class library项目 was set acceddentaly是一个控制台应用程序
因此,请确保您的类库项目是输出类型中的类库
小智 20
哦,我也在看这个问题.在我看来,解决方案太简单了.我在解决方案中添加了一个新的空项目.新添加的项目将自动设置为控制台应用程序.但由于添加的项目是一个"空"项目,因此该新项目中不存在任何Program.cs.(正如所料)
我需要做的就是将项目属性的输出类型更改为类库
我已经改变了
public static void Main(string[] args)
Run Code Online (Sandbox Code Playgroud)
到
public async static void Main(string[] args)
Run Code Online (Sandbox Code Playgroud)
问题是它需要是一个任务:
public async static Task Main(string[] args)
Run Code Online (Sandbox Code Playgroud)
我有这个错误并通过这个解决方案解决了。
--> Right click on the project
--> and select "Properties"
--> then set "Output Type" to "Class Library".
Run Code Online (Sandbox Code Playgroud)
检查项目的属性.在"应用程序"选项卡上,选择您的Program类作为启动对象: