Creating an Assembly Using C#

Introduction
 
This blog explains some steps and methods to create an assembly using c# in Visual Studio.  There are two methods available in .net framework for creating assembly one is Visual Studio Command Prompt and other is Integrated Development Environment (IDE). Lets discuses about these methods
 
Visual Studio Command Prompt: You can create an assembly at the command prompt by using command-line compilers. To do this, type the code at the command prompt. To create an assembly with the .exe extension at command prompt, use the following syntax:
 
Compiler command module name 
 
In this syntax, compiler command is the command for the language used  in your code module, and module name is the name of the code module that you   want to compile into the assembly.
 
For example, if you want to compile a code module called myCode into a assembly you can type the following command:
 
In Visual Basic
 
Vbc myCode.vb
 
In C#
 
Csc myCode.cs
 
Integrated Development Environment (IDE): You can also create assemblies by using the IDE such as Visual Studio  .NET 2005. After creating a project in the IDE, you can use the Build command on the toolbar to create an assembly. You must select the appropriate programming language, Visual Basic or C# while creating a new project to wnsure that the correct that the correct syntax options are used while creating the assembly. 

Steps to Create Assemblies
 
The following are the steps to create single-file and multifile assemblies in C#.
 
Create a source code file containing the following code example:

Class Greeting

{
     Public static void Main(string[] args)

     {

         Console .WriteLine("Welcome to C# world");

         Console.ReadLine() ;

     }
}


Save the source code file with the .cs extension. For example, for the above code example, save the file as Greeting.cs
 
Execute the csc assemblyname.cs command. This generates  file called assemblyname.exe. for example,for the above code execute the following command  from the command prompt:
 
Ese Greeting.cs
 
This generates the Greeting.exe file.
 
To execute this file, type the  file name, Greeting.exe, at the command prompt.
 
You will get the string Welcome to C# world.
 
Multiple assemblies
 
Create a source code file containing the following code example:

Using System;

Public class Student

{
    Public string FName;

    Public vold Show()

    {

        Console .WriteLine("student Name " + FName) ;

    }

}

 

Save the file as Student.cs. In this examplw, the Student class has a pumliv field called FName to store the full name of the student and a method called  Show  to print the value of an object of the Student class on the screen.
 
Save the code and compile it into module by using the following command:
 
Csc/t:module modulename .cs
 
For example, type the following at the command prompt:
 
Csc /t:module Student.cs
 
This generates a .netmodule called Student.netmodule.
 
Create the main source file and safe it in a sourcefilename.cs file. For this example, typing the following code example:

Using System;

Class MainClass

{
    Public static void Main(string[] args)

    {

         Student std = new Student() ;

         Std .FName ="Tony Allen";

         Std .Show();

    }

}

 

Save the file as MainClass.cs. In the main method of the above class, you create an instance std of the student  slass, which is present in the Student.cs file and assign the  value ony Allen to its member FName.
 
Summery
 
in the above discussion, we came to know how assemblies are created using Visual Studio Command Prompt and Integrated Development Environment (IDE) Method
Next Recommended Reading How to Create CSV File using C#?