简体   繁体   中英

CodeDOM compilation no errors but fails to launch console

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.

我从CompilerOptions中删除了/ target:winexe,现在可以使用了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM