0

I'm trying to create a Windows Form Application, that can create another Windows Form Application. But the error i'm getting when i'm trying to compile with CodeDom in the c# code, is a weird one.

'kjpUnityGameLauncherTemplate.RunLauncher' does not have a suitable static Main method

This kinda confuses me, since the class "RunLauncher" DOES have a main method, with the default setup described at the (http://msdn.microsoft.com/) site.

RunLauncher class: http://pastebin.com/NU3VYwpv (which have the main method)

The code i'm using to actually compile this via. CodeDom is this:

if (codeProvider.Supports(GeneratorSupport.EntryPointMethod))
{
    parameters.MainClass = "kjpUnityGameLauncherTemplate.RunLauncher";
}

CodeCompileUnit compileUnits = new CodeCompileUnit();
CodeNamespace nsp = new CodeNamespace("kjpUnityGameLauncherTemplate");

parameters.CompilerOptions = "/main:kjpUnityGameLauncherTemplate.RunLauncher";

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

nsp.Imports.Add(new CodeNamespaceImport("kjpUnityGameLauncherTemplate"));
compileUnits.Namespaces.Add(nsp);
CompilerResults results = icc.CompileAssemblyFromDom(parameters, compileUnits);

Theres some other stuff like declaration of the variables "codeProvider" etc. but those aren't the problem in this case, which is why I didn't include them.

4

1 回答 1

1

To Create an Executable Your code must have an Entry Point Method declared and set properly to run in CodeDom. I do not see one declared in your example above. Below I have an example from MSDN located at

http://msdn.microsoft.com/en-us/library/y2k85ax6.aspx

CodeEntryPointMethod start = new CodeEntryPointMethod();
CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("System.Console"),
"WriteLine", new CodePrimitiveExpression("Hello World!"));
start.Statements.Add(cs1);
于 2013-10-29T19:34:03.543 回答