How to Get a Free C# Command Line Compiler

How to Get a Free C# Command Line Compiler

When you buy Visual Studio 2005, you get the full-featured integrated development environment (IDE). If you don’t have Visual Studio 2005, You can also get a free C# compiler by using one of the following options:
You can get the command-line compiler (csc.exe) from Microsoft site
Download the redistributable package of the .NET Framework, which includes the compiler and the .NET Framework with C# 2005 syntax support.

Compiling with the compiler comes with the .NET Framework.

If you downloaded the C# command-line compiler only, you must include it in the path before using it. Do this by adding the location of the compiler to the PATH variable in the Windows environment. The compiler is located in the following
%windir% is the environment variable that indicates the location of the Windows directory. If you are using Windows XP, this variable is replaced by C:\WINDOWS.
<version> is the version of the .NET Framework. The latest version is v3.0 and 3.5 beta 2 also available, the location will be "%windir%\Microsoft.NET\Framework\<version>"
To add the location of the compiler to the path, use the following steps:
press window’s button + R Run… Dialog box will appear then run “cmd” you will get Command Prompt
When the Command Prompt window opens,if not on root directory type cd\ and then set path enter the following command:
set path=%path%;%windir%\Microsoft.NET\Framework\<version>

Now you can run your any C# source code from command prompt. Now we take an example. Open notepad(window’s button + R and type notepad for more shortcut see… Collection of useful command run on Command Prompt) and paste following code in it and save as FirstExample.cs
Remember one thing your file name and class name must be same.

Run Command

// The first program in C#
class FirstProgram
static void Main()
System.Console.WriteLine("Hello, My First Program on Command line using free C# compiler!");

Now open command prompt and compile FirstExample.cs

csc FirstExample.cs( for compile )
FirstExample (for Running compile fle)

see details I have got after compiling FirstExample.cs

Program Output

Further Reading

Leave a Reply

Your email address will not be published. Required fields are marked *