Targeting the C# Platform

The haxe compiler can generate C# source code from your haxe code.

After the installation Haxe, you need to issue the following command to install the hxcs library.

haxelib install hxcs

Hxcs is responsible for generating to C# code from Haxe code. To compile the generated C# source code you will need C# installed for cross platform development. We recommend installing the mono sdk and possibly monodevelop from the mono download page. Monodevelop can be setup to code any haxe target using the haxe language bindings, but currently the ideal workflow for C# target is not yet there, and we advise you start with a simple code editor such as SublimeText2, and compile from the command line.

Generating the C# source code

Let's see our first 'Hello world' example :
class Test 
    public static function main() 
        trace("Hello world");
  • Create a new folder and add a file named 'Test.hx' (with the script from above).
  • In the same folder, create a file named 'build.hxml' with the following content:
-cs test
-main Test
-D haxe3
  • Double click the build.hxml file or run it from commandline:
    haxe build.hxml

    The haxe compiler will output the generated C# source code to the test folder, and output the compiled C# to an application/executable called test.exe in the test/bin folder.

Running your application

From commandline:

cd test/bin
mono test.exe

You should see:

Main.hx:5: Hello world

You could modify your build.hxml file to do everything in one go with some debug information, which could be very useful given the new nature of the C# target.

-cs test
-main Test
-D haxe3
-cmd cd test/bin
-cmd test test.exe


C# generator supports following configuration defines:
  • -D no-compilation : only generate C# code, skip execution of actual C# compiler
  • -D no-root : place haxe runtime classes (like Array) in a separate namespace (haxe.root) instead of root
  • -D real-position : don't include #line directives with pointers to Haxe files. useful if you wan't to read generated code or debug something in that code


The C# target is still under development, don't hesitate to report issues here.
version #19775, modified 2013-09-24 04:28:34 by nadako