2013-10-29 112 views
0

所以我想通过C#/ CodeDom脚本编译/构建一个可执行文件。CodeEntryPointMethod不能与Winforms一起工作

我想要新的应用程序(被编译的一个)设置为它的主要方法,使用像Application.Run()一些方法来实际运行Windows窗体应用程序。

,我得到了错误:

原始类型kjpUnityGameLauncherTemplate.Launcher是无效的。因此你应该考虑使用CodeObjectCreateExpression。

我不明白,因为我被告知,这是我应该写的,运行方法。有人还告诉我,CodeEntryPointMethod已经具有默认的Main方法,因此我只需要添加“Application.Run()”方法等,但这正是我所听到的。

CodeTypeDeclaration class1 = new CodeTypeDeclaration("RunLauncher"); 

CodeEntryPointMethod start = new CodeEntryPointMethod(); 
CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("Application"), "EnableVisualStyles"); 
CodeMethodInvokeExpression cs2 = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("Application"), "SetCompatibleTextRenderingDefault", new CodePrimitiveExpression(false)); 
CodeMethodInvokeExpression cs3 = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("Application"), "Run", new CodePrimitiveExpression(new Launcher())); 

start.Statements.Add(cs1); 
start.Statements.Add(cs2); 
start.Statements.Add(cs3); 

class1.Members.Add(start); 

这不得不说,是“新发射器()”中的Application.Run(要运行)就像如果你有一个正常的Program.cs脚本,运行Form1类运行应用程序。我希望这至少是有道理的。

回答

1

CodePrimitiveExpression适用于基本类型,如intstring。我认为你想要创建Launcher类的实例:

//new Launcher() 
new CodeObjectCreateExpression("Launcher", new CodeExpression[] {})