Posted in
c#,
create,
Design,
exe,
executable,
execute,
export,
generate,
IO,
make,
Output,
programmatically,
save
I was thinking of making a program that generates an executable which installs an application, but how to generate the executable?
In order to use this function, you must using these two classes:
Once you have that done, you're good to go! As a quick example, you can create a textarea named txt_code, a textbox named txt_output, and a button btn_submit. When btn_submit is clicked, then it will say:
Compile(txt_output.Text, txt_code.Text);
Which if you put a valid path in txt_output, and valid C# code in txt_code, then you will have your executable!
Original Article Here
public static void Compile(String Output, String code) { CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp"); CompilerParameters parameters = new CompilerParameters(); //Make sure we generate an EXE, not a DLL parameters.GenerateExecutable = true; parameters.OutputAssembly = Output; CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, code); if (results.Errors.Count > 0) { foreach (CompilerError CompErr in results.Errors) { Debug.WriteLine( "Line number " + CompErr.Line + ", Error Number: " + CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";" + Environment.NewLine + Environment.NewLine); } } else { Debug.WriteLine("Success!"); } }
In order to use this function, you must using these two classes:
using System.CodeDom.Compiler; using System.Diagnostics;
Once you have that done, you're good to go! As a quick example, you can create a textarea named txt_code, a textbox named txt_output, and a button btn_submit. When btn_submit is clicked, then it will say:
Compile(txt_output.Text, txt_code.Text);
Which if you put a valid path in txt_output, and valid C# code in txt_code, then you will have your executable!
Original Article Here