I have created my project and now want to compile using a CodeDOM compiler. I have a folder full of the .CS files that should be compiled to an EXE. The application is supposed to be a console application although it fails to launch any console. There are no building errors. The following is my compile method:
public static void Build(string AssemblyName, string OutputDirectory, string[] SourceFiles)
{
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.GenerateInMemory = false;
parameters.ReferencedAssemblies.Add("System.dll");
parameters.ReferencedAssemblies.Add("System.Data.dll");
parameters.ReferencedAssemblies.Add("System.Xml.dll");
parameters.OutputAssembly = OutputDirectory + @"\" + AssemblyName + ".exe";
parameters.CompilerOptions = "/unsafe /target:winexe /platform:x86";
if (codeProvider.Supports(GeneratorSupport.EntryPointMethod))
{
parameters.MainClass = "MyApp.Program";
}
CompilerResults results = codeProvider.CompileAssemblyFromFile(parameters, SourceFiles);
if (results.Errors.Count > 0)
{
foreach (CompilerError error in results.Errors)
Console.WriteLine(error.ErrorText);
}
}
string[] SourceFiles
correctly provides all .CS files (classes, structs and enums) located in the folder like follows:
"D:\\Development\\MyAppCodeDom\\Program.cs"
"D:\\Development\\MyAppCodeDom\\IniParser.cs"
And 26 more of those. I do not use any external DLL files as reference whatsoever. It fails, however, to launch the console window.
Any idea? Perhaps a console application requires certain options?
EDIT: Using ILSpy, the assembly seems to contain ALL the classes etc it should have.
Thank you in advance.
I removed /target:winexe from the CompilerOptions and now it works.