X
Tech

Running .NET on Linux

Who said .NET only runs on Windows? In this article we take a look at DotGNU and how you can get .NET applications running on Linux and other flavours of Unix.
Written by David McAmis, Contributor
Who said .NET only runs on Windows? In this article we take a look at DotGNU and how you can get .NET applications running on Linux and other flavours of Unix.
One of the disadvantages of using Visual Studio.NET and the .NET framework to develop applications has been the lack of cross-platform support. Since the introduction of the .NET framework and common language run time a few years ago, there have been a few projects designed to bring the .NET framework to other platforms, including Linux and Unix.
We looked at one of these projects earlier, with our tutorial on "Using Mono for .NET Linux Development" and in this article, we are going to be looking DotGNU, the other major project designed to bring .NET to other platforms.
The DotGNU project is touted as the "Free software alternative to .NET" and encompasses a number of projects, including DotGNU Portable .NET, which is designed to be used to compile and run C# and C applications on a multitude of platforms, including GNU/Linux, FreeBSD, Mac OS X, and Windows.
One of the main features of the product is it's compatibility with EMCA standards for C# and the Common Language Infrastructure (CLI), as well as Microsoft's own CLI implementation in the .NET framework.
The project chose to go with a "Virtual Machine" implementation, where bytecode is transformed into a simple instruction set which is then passed to a "Converted Virtual Machine", which then are executed through an interpreter. This approach is different to other open source .NET implementations, but provides more flexibility when porting the project to other platforms.
At the core of the project is the runtime engine (ilrun) and compiler (cscc) with an implementation of System.Windows.Forms that make developing for the platform easier, as it doesn't required translation through another toolkit or toolset.
But enough of the behind the scenes! In this tutorial we are going to look at how to get DotGNU Portable .NET up and running on RedHat Linux and how to run some of the sample applications that are available for this project.
Getting Started
To start, you will need to download either the DotGNU source code or binaries for your particular operating system. Since we are implementing DotGNU on Red Hat, I went the easy route and downloaded the appropriate RPM's from http://phillip.compton.name/pnet/, as shown below in Figure 1.

Figure 1: RPM's for DotGNU

In order to get DotGNU Portable .NET up and running, there are three required components that need to be installed, in the following order:
  • treecc
  • pnet
  • pnetlib

  • In addition, there are two optional components you may want to install for C support and support for the Mono libraries
  • pnetC
  • ml-pnet

  • On the download page we looked at earlier, some of these components have been split up into separate RPM files which you will need to install in order. Pay attention to the dependencies within these RPMS and resolve any conflicts before you proceed with the installation.
    Once you have these components installed, you can then download and run the sample applications that are available for the project to test your installation.
    Testing the Installation
    To test the installation, we are going to download and run the sample application that is available from the DotGNU web site. It is an implementation of the old Nim game, where you play against the computer to remove the pegs in order to have one peg left on the board. (Although don't ask me... I wasn't able to beat it once.)
    Once you have downloaded and unpacked the sample application, you can run it from a simple command line by typing "ilrun nim" to run the game which should look something like the screen shot below in Figure 2:

    Figure 2: Sample application

    And once you have verified that your sample application is working, you can get down to coding your very first DotGNU application. The documentation for the project is extensive with the DotGNU Wiki which is a good resource you can use to get started.
    Editorial standards