Friday, July 8, 2011

Write .NET "exe" with out Visual Studio installed

Here is a quick step to start compiling C# code from the command prompt and notepad. The other day I spent an hour learning how to do something I already know how to do in C# because I didn't have access to VS.NET. Granted most of that time was spent learning how to over come the limitations of the script language. You'll need to make sure the .NET framework is installed before you start.

1. Create a text file
2. Rename it to Program.cs
3. Open it in a text editor
4. Type your program:

using System;
namespace Example.HelloWorld
{
 class Program
 {
  static void Main()
  {
   Console.WriteLine("Hello World");
  }
 }
}

Notes on compiling:
* Find the C# conpiler "csc.exe", there should be several versions my current one is "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe"
- Type at the command-line: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe c:\yourPath\Program.cs
* Remember to type the full path to both the compiler and the *.cs file, you can add the compiler path to the "path" enviroment variable so you dont have to type it every time.
- Type at the command-line: csc.exe c:\yourPath\Program.cs

The ability to write create a "exe" is powerful....
Post a Comment