Domanda

So, I'm creating this application, that allows you to build a Windows Form Application without having to use the Visual Studio Build, but just doing it through code.

It works fine if I forget about other classes and the fact that the main class has to run "Application.Run();" to another class.

My problem is, that it says following:

Could not find 'RunLauncher' specified for Main method

I have a couple of scripts. The first one being the standard C# Script, that contains the Main method, to run the Windows Form C# Script, via. the Application.Run() method. This Windows Form C# Script, then have another class linked to it as an object (Created in the Load method), so there is basicly 3 scripts in total, that needs to be compiled into the new executable.

The main class "RunLauncher", that runs the method Application.Run() to run the Windows Form Application, runs the Launcher class, which is listed below.

I'm almost positive theres something wrong with the actual code to compile it and find the class, and not these classes, but for the sake of doubts, I've linked them anyway:

The compiling CodeDom code:

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);
È stato utile?

Soluzione

The problem is that there is no class called RunLauncher in the generated assembly. The class you want is called kjpUnityGameLauncherTemplate.RunLauncher, so that's what you need to set at the MainClass:

parameters.MainClass = "kjpUnityGameLauncherTemplate.RunLauncher";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top