Tuesday, April 10, 2012

Compiling a Module from the Command Console

Using Command line syntax to compile a type into a module

>csc.exe /out:Program.exe /target:exe Program.cs

which breaks down to:
csc.exe - C Sharp Compiler
/out:Program.exe - the output is an executable file called Program.exe
/target:exe - the target file type will be a Win32 console application
Program.cs - source code file  name

In this example the out and target switches match the defaults, so I could use
>csc.exe Program.cs


And this is a simple console app source code example

public sealed class Program {
  public static void Main() {
    System.Console.WriteLine("Hello World");
  }
}

And if you want to add a reference to a couple of dll's
/lib:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0" /r:UIAutomationClient.dll /r:UIAutomationTypes.dll