hey !
can someone help me to know how generate a .exe file from a c# program?
i tried these codes , but its not succesfull
AppDomain ad = AppDomain.CurrentDomain;
System.Reflection.AssemblyName an = new System.Reflection.AssemblyName();
an.Name = "Childprogram";
System.Reflection.Emit.AssemblyBuilder ab = ad.DefineDynamicAssembly(an, System.Reflection.Emit.AssemblyBuilderAccess.Save);
System.Reflection.Emit.ModuleBuilder mb = ab.DefineDynamicModule("testmodule", "Childprogram.exe");
System.Reflection.Emit.TypeBuilder tb = mb.DefineType("testtype", System.Reflection.TypeAttributes.Public);
System.Reflection.Emit.MethodBuilder metb = tb.DefineMethod("hi", System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.Static,null, null);
ab.SetEntryPoint(metb);
System.Reflection.Emit.ILGenerator ilg = metb.GetILGenerator();
ilg.EmitWriteLine("hiii worrld");
ilg.Emit(System.Reflection.Emit.OpCodes.Ret);
tb.IsCreated();
ab.Save("Childprogram.exe",System.Reflection.PortableExecutableKinds.ILOnly,System.Reflection.ImageFileMachine.IA64);
but it gives an error :
Type 'testtype' was not completed.
\
what is problem?
i also tried these codes :
Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.GenerateInMemory = false;
cp.GenerateExecutable = true;
cp.OutputAssembly = "Childprogram.exe";
System.CodeDom.Compiler.CompilerResults cr= cscp.CreateCompiler().CompileAssemblyFromFile(cp, @"a.cs");
if (cr.Errors.Count > 0) MessageBox.Show(cr.Errors.Count.ToString()+cr.Errors[0].ToString()+cr.Errors[0].FileName);
but this one give me error to that is saying i dnt have a static main method in Childprogram.exe !
wheras this is my sourcefile code :
using System;
namespace RDPCracker
{
static class Program
{
static void Main()
{
Console.WriteLine("asd");
}
}
}
what is problem?
very thanks to spend time for me!