This project is read-only.

Getting Started

CS2HX is a command-line utility that will work as part of any build process, any IDE, in any environment (including Linux and OSX via Mono.)

This guide is simply a suggested starting point on getting your first CS2HX project up and running. It is anticipated that you will customize this process to suit your needs.

This guide will assume you're using some version of Visual Studio and Flash Develop, but neither are required.

Step 1: (Optional) Create a separate project to convert

Typically, you only want to convert a subset of your C# code to haXe. To make this easier, it is often useful to create a separate project that points at the same source files as your current project.

Let's walk through an example project. This project is a Visual Studio 2008 console app that consumes some code. We plan to convert the CodeToConvert class to haXe, while leaving the console application functional. This will allow both the haXe and C# console applications to consume CodeToConvert, while we only had to write CodeToConvert once.

We will create two C# projects that point at the same folder. This technique is commonly used by Visual Studio users to allow two projects to compile the same code.


Create a Class Library project to hold all the code we wish to convert to haXe.


Delete the auto-generated Class1.cs file and AssemblyInfo.cs


Now, we're going to move the project so it's in the same folder as your existing project. First, remove the project from your solution:


Move the .csproj file from its current location into the same folder as your existing project.


Now in Visual Studio, add the haXe project back by using Add -> Existing Project and selecting the .csproj you just moved.


Select the haXe project, and click the "Show all Files" button.


Right-click the code you wish to convert, and select Include In Project.


Ensure the project builds. Since CS2HX reads directly from your source files, it's actually not necessary for your project to build without errors. However, it's usually a good idea to be able to build anyway since it assures you that your code is well-formed and allows post-build events to run.

Step 2: Download and extract CS2HX

Download the latest release of CS2HX and extract it somewhere. For our example, it will be in D:\Stuff\CS2HX\

Step 3: Create your haXe project

For this guide, we will create a new AS3 haXe project using FlashDevelop in d:\temp\haXeTutorial


Step 4: Set a post-build event that invokes CS2HX.exe

CS2HX has been tested on over 30,000 lines of C# code and it converts it all within just a few seconds. This makes it quite suitable for a post-build event. We will supply CS2HX.exe with two parameters:

1. Path to haXe's .csproj file: We will use the $(ProjectPath) visual studio command to automatically insert this path.
2. Output directory: This tells CS2HX where to place the haXe files. We will point this at our FlashDevelop src folder.

To set your post-build event, right click on the haXe project, select Properties. Then select Build Events. Our post-build event will be:

D:\Stuff\CS2HX\CS2HX.exe "/out:d:\temp\haXeTutorial\src" "/csproj:$(ProjectPath)"


Now build your haXe project and all of your code will be converted.

Step 5: Link supplemental haXe code

CS2HX provides haXe code to implement the base class libraries that exist in .net. This code supplements your converted haXe code. This code lives within the system directory of where you extracted CS2HX.

You can copy this system directory to your haXe src directory, but I recommend you use a link so your projects auto-update when CS2HX updates.

mklink /D system D:\Stuff\CS2HX\system

Note that mklink is not available on XP and older Windows operating systems. On XP and below, you must copy the directory manually.

Step 6: Done!

Now simply write your haXe code and run it.

import exampleproject.CodeToConvert;
class Main 
	static function main() 
		trace(new CodeToConvert().DoStuff(3));

You can examine your src directory to see the converted code.


Last edited Mar 2, 2010 at 10:41 PM by fickerra, version 2


No comments yet.