Question

So I'm trying to compile/build an executable through C#/CodeDom Scripting.

I'm trying to have the new application (The one to be compiled) set to have it's main method, to use some methods like Application.Run() to actually run the Windows Form Application.

The error that I got:

Primitive Type kjpUnityGameLauncherTemplate.Launcher is invalid. You should therefore consider using CodeObjectCreateExpression.

Which I don't understand, since I got told, that this is what I'm supposed to write, to run the methods. Someone also told me that the CodeEntryPointMethod already have the Main method as default, and therefore I only need to add the "Application.Run()" method and such, but that's just what I've heard.

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);

It has to be said, that the "new Launcher()" to be run in the Application.Run() is just like if you had a normal Program.cs script, running the Form1 class to run the application. I hope that makes sense atleast.

Was it helpful?

Solution

CodePrimitiveExpression is for primitives like int or string. What I think you want is to create an instance of your Launcher class:

//new Launcher()
new CodeObjectCreateExpression( "Launcher", new CodeExpression[] {} )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top