Thursday, October 8, 2009

Compilation in C# (.Net Framework)

In this article you will find an idea how a C# compiler executes in .Net.

The C# compiler compiles source code, specified as a set of files with the .cs extension, into an assembly. An assembly is the unit of packaging and deployment in .Net, and it can be either an application or a library. A normal console or Windows application has a Main method and is an .exe. A library is a .dll, and is equivalent to an .exe without an entry point. Its purpose is to be called upon (referenced) by an application or by other libraries. The .Net Framework is a set of libraries. (Think of a library as a tool to be used in an application that provides a certain function or task for the program.)

The name of the C# compiler is csc.exe. You can either use an IDE such as Visual Studio.Net to call csc automatically, or compile manually from the command line. To compile manually, first save a program to a file such as MyProgram.cs, and then invoke csc (located under /Microsoft.Net/Framework) from the command line, as follows: This produces an application named MyProgram.exe. To produce a library (.dll), you'd do the following:

csc /target:library MyProgram.cs

Try this one and find out how C# compiles in .Net.

No comments:

Post a Comment