Mobile Software Engineering

2007-10-17 by tamberg

Compiling C# Without Visual Studio

Using a state of the art software development environment might boost your productivity - at least if it’s measured in lines of code. However, to understand what is going on behind the scenes using the command line C# compiler csc may be the better choice. Consider this example resulting in a library A.dll and a client program B.exe that references it.

// A.cs

using System;

public sealed class A {
    
  A () {}

  public static void P () {
    Console.WriteLine("A.P");
  }

}

// B.cs

using System;

sealed class B {

  B () {}

  static void Main () {
    Console.WriteLine("B.Main");
    A.P();
    Console.ReadLine();
  }

}

To compile, save the above .cs files and run the following batch file.

REM make.bat

PATH C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\
csc /checked /t:library A.cs
csc /checked /t:exe B.cs /r:A.dll
PAUSE

Note the /checked compiler option, which should be the default but unfortunately is not.