【发布时间】:2013-10-29 01:47:33
【问题描述】:
所以,我正在创建这个应用程序,它允许您构建 Windows 窗体应用程序,而无需使用 Visual Studio Build,而只需通过代码来完成。
如果我忘记了其他类以及主类必须运行“Application.Run();”这一事实,它工作得很好到另一个班级。
我的问题是,它说如下:
Could not find 'RunLauncher' specified for Main method
我有几个脚本。第一个是标准 C# 脚本,它包含 Main 方法,用于运行 Windows 窗体 C# 脚本,通过。 Application.Run() 方法。这个 Windows 窗体 C# 脚本,然后有另一个类作为对象链接到它(在 Load 方法中创建),所以基本上总共有 3 个脚本,需要编译成新的可执行文件。
运行方法 Application.Run() 以运行 Windows 窗体应用程序的主类“RunLauncher”运行下面列出的 Launcher 类。
我几乎可以肯定,编译它并找到类的实际代码有问题,而不是这些类,但出于疑问,我还是将它们链接起来:
- 新可执行文件的主类 | http://pastebin.com/NU3VYwpv
- 启动器 Winform C# 类 | http://pastebin.com/gQwV923g
编译 CodeDom 代码:
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
string Output = game_filename.Text + ".exe";
Button ButtonObject = (Button)sender;
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
parameters.ReferencedAssemblies.Add("System.dll");
parameters.ReferencedAssemblies.Add("System.IO.Compression.dll");
parameters.ReferencedAssemblies.Add("System.IO.Compression.FileSystem.dll");
if (codeProvider.Supports(GeneratorSupport.EntryPointMethod))
{
parameters.MainClass = "RunLauncher";
}
CodeCompileUnit compileUnits = new CodeCompileUnit();
CodeNamespace nsp = new CodeNamespace("kjpUnityGameLauncherTemplate");
compileUnits.Namespaces.Add(nsp);
nsp.Imports.Add(new CodeNamespaceImport("kjpUnityGameLauncherTemplate"));
CodeTypeDeclaration class1 = new CodeTypeDeclaration("RunLauncher");
nsp.Types.Add(class1);
CodeTypeDeclaration class2 = new CodeTypeDeclaration("kjpUnityGameLauncher");
nsp.Types.Add(class2);
CodeTypeDeclaration class3 = new CodeTypeDeclaration("Launcher");
nsp.Types.Add(class3);
CompilerResults results = icc.CompileAssemblyFromDom(parameters, compileUnits);
【问题讨论】:
-
您对问题的编辑显着改变了您的要求,并使现有答案无效。这不是堆栈溢出的工作方式。如果您有新问题,ask a new question。
-
那么公平。创建了一个新问题(与此目的几乎相同),但如果这是 Stackoverflow 的工作方式,我不会改变它:) 无论如何感谢您的帮助。
标签: c# .net winforms compilation codedom