【发布时间】:2013-06-10 08:00:08
【问题描述】:
当我尝试使用 CodeDom 编译源代码时出现此错误
不包含适合入口点的静态“Main”方法!
我已经用谷歌搜索过它并在这里阅读了其他答案,但我不知道如何解决它。
有人可以帮帮我吗? 这是我的源代码: 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.");
}
}
【问题讨论】:
-
错误的哪一部分你不明白?
-
提示:msdn.microsoft.com/en-us/library/acy3edy3(在 Google 上搜索
C# main) -
您可以在您的问题中发布该代码吗?
-
@SLaks 我理解错误,但我不知道如何修复它。我已经尝试在源代码中添加一个名为 main 的静态方法,但它不起作用,因为我得到一个新的错误...
-
肯定不好笑,但是有点好笑