当我尝试使用 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.");
}
}