Skip to content
Tags

Compiling .cs files from the Command Line

by on July 12, 2012

You can write and compile your C# programs directly from the command line.

If you need to test something quick and don’t have Visual Studio or anything installed. Simply open the Command Line and create your program using notepad.exe like so:

C:\>notepad hello.cs

This will open Notepad and create the file hello.cs in the current
working directory (CWD) of the command line.

From there, create your simple program in notepad and save it.
Here’s an example:

using System;

public class Program
{
   public static void Main()
   {
        console.WriteLine("Hello World!");
   }
}

From there, save the file and in the command line you can compile
the file using your .NET framework installation
In the example i’m using .NET 4

C:\>c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe hello.cs

Once you run the C# compiler (csc.exe) you will find a new
executable in your CWD called hello.exe.
You can now run this and it will run the code you wrote in
your hello.cs file.

From → C#

Leave a Comment

Leave a comment

NE1 Atoll

The Official blog of NE1 Games

Selenium for .Net using C# language

Adventures in Coding, gaming and other fun things in my life

Coded UI 101 - Understanding Coded UI Tests

Adventures in Coding, gaming and other fun things in my life