错误"不包含静态"主营"适合的切入点方法 [英] Error "Does not contain a static "Main" Method suitable for an entry point
问题描述
我得到这个错误时,我尝试编译的CodeDOM一个源代码
不包含适合于静态的主方法入口点!
块引用>
我已经用Google搜索,并在这里阅读其他的答案,但我不知道如何解决它。
有人能帮帮我吗?
这里是我的源代码:
http://picz.to/image/ao5n一>^私人无效button2_Click(对象发件人,EventArgs五)
{
SaveFileDialog D =新SaveFileDialog();
d.Filter =可执行文件(* .exe)| * .exe的;
如果(d.ShowDialog()== DialogResult.OK)
{
串源= Properties.Resources.source;
CompilerParameters参数=新CompilerParameters();
param.CompilerOptions + =/目标:winexe++/ win32icon:+\+ textBox1.Text +\;
param.GenerateExecutable = TRUE;
param.ReferencedAssemblies.Add(System.Windows.Forms.dll中);
param.ReferencedAssemblies.Add(System.dll中);
param.OutputAssembly = d.FileName;
StringBuilder的温度=新的StringBuilder();
字符串InputCode =的String.Empty;
InputCode =MessageBox.Show((1 + 2 + 3)的ToString());;
Temp.AppendLine(@使用系统;);
Temp.AppendLine(@使用System.Windows.Forms的;);
Temp.AppendLine(@命名空间RunTimeCompiler {);
Temp.AppendLine(@静态无效的主要(字串[] args){);
Temp.AppendLine(@公共类的测试{);
Temp.AppendLine(@公共无效Ergebnis(){);
Temp.AppendLine(InputCode);
Temp.AppendLine(@}}}});
CompilerResults结果=新CSharpCodeProvider()CompileAssemblyFromSource(参数,Temp.ToString());如果
(result.Errors.Count大于0)的foreach(在result.Errors CompilerError ERR)MessageBox.Show(err.ToString());
,否则MessageBox.Show(完成。);
}
}
解决方案所有C#程序需要包含Main()方法。本质上,这是程序的开始。您发布的代码是整个应用程序的只是一小部分。您必须去掉的主曾居住的位置。
的在主 MSDN文章
更新了意见:
一个新的Windows窗体应用程序有一个实例化所需的表单程序类。
静类节目
{
///<总结>
///的主入口点应用程序。
///< /总结>
[STAThread]
静态无效的主要()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(假);
Application.Run(新Form1中());
}
}
尝试复制该到一个被称为新文件。 CS。确保Form1中现在指向您在应用程序中创建表单。
I got this Error when I try to compile a sourcecode with CodeDom
Does not contain a static "Main" Method suitable for an entry point!
I already googled it and read other answers here, but I dont know how to fix it.
Can someone please help me? Here is my source code : http://picz.to/image/ao5n
^ private void button2_Click(object sender, EventArgs e) { SaveFileDialog d = new SaveFileDialog(); d.Filter = "Executable (*.exe)|*.exe"; if (d.ShowDialog() == DialogResult.OK) { string source = Properties.Resources.source; CompilerParameters param = new CompilerParameters(); param.CompilerOptions += "/target:winexe" + " " + "/win32icon:" + "\"" + textBox1.Text + "\""; param.GenerateExecutable = true; param.ReferencedAssemblies.Add("System.Windows.Forms.dll"); param.ReferencedAssemblies.Add("System.dll"); param.OutputAssembly = d.FileName; StringBuilder Temp = new StringBuilder(); String InputCode = String.Empty; InputCode = "MessageBox.Show((1 + 2 + 3).ToString());"; Temp.AppendLine(@"using System;"); Temp.AppendLine(@"using System.Windows.Forms;"); Temp.AppendLine(@"namespace RunTimeCompiler{"); Temp.AppendLine(@"static void Main(string[] args){"); Temp.AppendLine(@"public class Test{"); Temp.AppendLine(@"public void Ergebnis(){"); Temp.AppendLine(InputCode); Temp.AppendLine(@"}}}}"); CompilerResults result = new CSharpCodeProvider().CompileAssemblyFromSource(param, Temp.ToString()); if (result.Errors.Count > 0) foreach (CompilerError err in result.Errors) MessageBox.Show(err.ToString()); else MessageBox.Show("Done."); } }
解决方案All C# programs need to contain the Main() method. Essentially this is where the program starts. The code you posted is just a small part of the entire application. You must have removed the location where main had been residing.
Updated for comments:
A new Windows Form App has a Program class that instantiates the form that you want.
static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }
Try copying that over to a new file called program.cs. Make sure that Form1 now points to the form you created in the applications.
这篇关于错误"不包含静态"主营"适合的切入点方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!