READ DIGITAL EDITION


ADS BY GOOGLE
TOP THREE LINKS YOU MUST CLICK ON


Getting Started in Linux for the Experienced .NET Developer
Get your applications ready for the world's fastest-growing OS

As an experienced .Net developer, I'm sure you are comfortable creating programs in your home environment - using Visual Studio on a Windows PC. What about using other platforms? In the .NET world, not many developers think much about cross-platform development. However, with the growing popularity of Unix, and specifically Linux, as a server platform, it might be time to consider a cross-platform .NET development environment.

You may not even be aware that there are options for .NET developers in the Linux world. Much of the .NET work in Linux is a result of Microsoft's attempt to standardize the C# language by submitting it to the ECMA. With an international standard for .NET programming, many open source organizations are starting to look at the .NET development environment on non-Windows systems.

The trick to .NET development in Linux is to build the proper development platform. There are a few different options for creating .NET applications on Linux, and trying to put the pieces together can be complicated, especially if you are new to the Linux world. This article will help take some of the complexity out of the process, and show the first steps toward plunging into .NET in Linux.

.NET in Linux
There are several different groups that are working on porting the .NET specifications to open source environments. By far the most popular .NET implementation in Linux is the Mono project.

Although it does not necessarily have a good connotation in the English language, mono is derived from the Spanish word for monkey, its official mascot. The Mono package is making great strides in implementing much of the .NET framework on an open source environment. The current version of Mono (1.1.9) includes:

  • A Common Language Infrastructure (CLI) to run .NET applications
  • A .NET-compatible class library
  • Class libraries to support Linux-specific functions
  • A C# compiler
  • Two ASP.NET Web servers
  • Dozens of .NET utilities
These are all of the pieces you need to compile and run C# .NET applications in Linux. Now all you need is a Linux platform on which to install Mono.

Creating a Linux Environment
Getting started in a Linux environment can be a confusing venture. Unlike Microsoft, where the workstation and server environments are pretty much set for you, there are lots of different options available in the Linux world.

First off, if you have been looking to install Linux, you probably already know that there are literally hundreds of different Linux distributions available. A Linux distribution is a prepackaged set of Linux utilities and applications that when put together create a Linux environment. Different distributions combine different sets of utilities and applications. Your first decision is which distribution is right for your purposes (.NET development). The Mono project recommends a few different Linux distributions:

  • Red Hat Linux
  • Fedora Core Linux
  • SuSE Linux (owned by Novell)
Both SuSE and Fedora are available as supported commercial packages, and unsupported free downloads. If you are just dabbling in Linux, you can freely download the SuSE and Fedora installation CDs and try them out with Mono.

The Live Linux CD
A great feature of Linux is the boot-able CD. This is a CD that contains a pre-installed Linux distribution. Booting your PC from the live CD automatically starts and runs Linux with little or no effort on your part!

There is a Live Linux CD specifically for Mono users. The Monoppix live CD (www.monoppix.com) can be freely downloaded. This is a painless way to test-drive both Linux and Mono without having to build a PC for it.

Installing Mono
If you choose to install a Linux distribution on your PC, you must manually install Mono. The Mono Web site (http://mono-project.com) contains several download options for getting the Mono package. With all of the different possibilities in the Linux world, there are lots of different installation options.

The Mono project provides specific install packages for the Red Hat, SuSE, and Fedora Linux distributions. These packages install Mono on the target PC without any intervention from you. This is by far the easiest way to install Mono.

If you already have a Linux distribution installed, but is not directly supported by one of the Mono installation packages, don't worry - there is still an option for you. Besides the standard install packages, Mono also has a generic binary installer program. The generic installer program installs Mono into a folder of your choice on your Linux system. This enables you to install multiple versions of Mono on the same PC. This is great for testing your software with different Mono release levels.

Using Mono
Once Mono is installed, it's time to test it out. The Mono package contains several different command-line utilities for working in the .NET environment. The most important for developers is mcs, the Mono C# compiler.

Let's take a C# program to put the Mono installation through its paces. Listing 1 shows a sample C# program (SampleClass.cs) that uses two classes, one as an internal data class, and the other to support the Main method.

To build the program using Mono, use the mcs compiler. From a Linux command line type:

$ mcs SampleClass.cs
$

The compile should complete with no errors. The output of the compile is the executable program SampleClass.exe (note that the executable program maintains the Windows .exe suffix, even though it was built on a Linux platform).

You can run the SampleClass.exe program on either a Linux or Windows platform. To run it on the Linux platform, you must use the Mono runtime program, mono:

$ mono SampleClass.exe 10 5
The result is 15
$

Congratulations, you just compiled and ran your first .NET program on a Linux system!

Getting Graphical
It is crucial to be able to create graphical windows applications in a .NET development environment. This is one area where Mono is still trying to catch up. Unfortunately, there have been several failed attempts in Mono to implement the System.Windows.Forms class libraries. However, it is starting to look as though there is light at the end of the tunnel.

Mono has started the Managed.Windows.Forms class, which implements most of the System.Windows.Forms class methods using the standard System.Drawing classes. While this may still not be the best approach, it certainly has gotten farther than any other approached tried to date.

The problem with creating graphical classes in Mono is the wide variety of graphical environments in Linux. It is difficult to find a common graphical API set from which to build the .NET classes.

Besides the standard System.Windows.Forms classes, Mono also includes two other classes for windows programmers: GTK# and Cocoa#. As the name implies, the Cocoa# classes are used for writing windows applications on the Mac OS X platform. These windows are 100 percent compatible with the standard Mac windows look and feel.

About Richard K. Blum
Richard Blum currently works for a large US government organization as a network and systems administrator. He is the author of C# Network Programming (2002, Sybex) and Professional Assembly Language (2005, Wrox).

  Subscribe to our RSS feeds now and receive the next article instantly!
In It? Reprint It! Contact advertising(at)sys-con.com to order your reprints!
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS

ADS BY GOOGLE
IBM is going to buy Transitive, the British cross-platform virtualization firm that salvaged legacy ...
Capgemini has announced an agreement signed between Capgemini UK plc and Amazon Web Services, extend...
Focusing your service-oriented architecture (SOA) performance management efforts on the application ...
rPath has announced support for the Ubuntu and CentOS Linux operating systems as part of rBuilder an...
Adobe and ARM are gonna put Flash Player 10 and AIR, the stuff of web video and rich Internet apps, ...
We are using software applications more than ever before. As the demand for new capabilities and fun...
Symantec has announced Veritas Operations Services, a new cloud computing-based online services plat...
CA and VMware are going to jointly develop a management solution and, to start, have signed a deal t...
Appistry announced findings from the first in a series of surveys the two organizations are conducti...
HP jumped the gun Tuesday and told the worried multitudes a week ahead of when it’s supposed to re...
AppSense, the leading provider of user environment management solutions for the enterprise, will be ...
Amazon has launched an HTTP content delivery service (CDN) called CloudFront that works with its S3 ...
Are you a victim of outdated call center design syndrome? Symptoms include chaotic agent desktops, f...
LynuxWorks has announced immediate availability of LynxSecure 2.0, a next-generation separation kern...
SOA brings together people, not just software. That’s why integrating Web 2.0 concepts into a SOAâ...
XAware has announced that Kirstan Vandersluis, founder and chief scientist, will be a featured speak...
OpenSpan and TIBCO have announced a technology and business partnership designed to extend TIBCO sol...
The Java Community Process (JCP) Program Management Office has announced the final results of the 20...
Hadoop, an open source implementation of map/reduce, has garnered tremendous momentum in large scale...
I spoke on a panel at Mashup Camp this week on why Ajax Standards matter. I was quoted by Doug Hensc...