C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to Create Executable (exe) files using Console Applications in C#


Posted Date: 20 Mar 2008    Resource Type: Articles    Category: .NET Framework

Posted By: MuniHemadriBabu.Jogi       Member Level: Gold
Rating:     Points: 8



System.Runtime.Emit namespace provides necessary classes to create an executable (.EXE) file on-the-fly.


After compiling this code sample and run it on the Console. A new file is generated in your folder called TestAsm.exe. This EXE file print's a message "Hello World" on the Console.



using System;
using System.Runtime;
using System.Runtime.Emit;
class RuntimeEmit
{

public static void Main(String [] args)
{
AppDomain ad = AppDomain.CurrentDomain;
AssemblyName am = new AssemblyName();
am.Name = "TestAsm";

AssemblyBuilder ab = ad.DefineDynamicAssembly(am,AssemblyBuilderAccess.Save);
ModuleBuilder mb = ab.DefineDynamicModule("testmod","TestAsm.exe");
TypeBuilder tb = mb.DefineType("mytype",TypeAttributes.Public);
MethodBuilder metb = tb.DefineMethod("hi",MethodAttributes.Public | MethodAttributes.Static,null,null);
mb.SetEntryPoint(metb);
ILGenerator il = metb.GetILGenerator();
il.EmitWriteLine("Hello World");
il.Emit(OpCodes.Ret);
tb.CreateType();
ab.Save("TestAsm.exe");
}
}



  • Save this file as RuntimeEmit.cs and
  • Compile C:/>csc RuntimeEmit.cs
  • Run this file C:\>RuntimeEmit
  • To run the Exe file generated, here is the command



C:\>TestAsm





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Use Runtime.Emit to create exe files  .  Use Console Applications to Create Executable files  .  Create Executable Files in C# from Console Applications  .  Create Executable Files in C#  .  Create Executable Files from Console Applications  .  Create exe files in C#  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: IsPageRefresh in ASP .NET
Previous Resource: ADO.Net
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use