Richard K. Blum

Subscribe to Richard K. Blum: eMailAlertsEmail Alerts
Get Richard K. Blum: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Apache Web Server Journal

Apache Web Server: Article

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.

More Stories By 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).

Comments (5) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Joe Jones 11/12/05 12:02:36 PM EST

David,

I agree with you completely. WinForms is the key.

David J. McKee 11/11/05 01:31:07 PM EST

http://crossplatformdotnet.blogspot.com/2005/11/getting-started-in-linux...

Owen 11/10/05 10:27:34 AM EST

Gtk# _is_ Windows compatible. Just take a look at the home page: http://gtk-sharp.sourceforge.net/. Mono is a lot closer to being cross platform than Microsoft's implementation.

Gtk+ also works on Windows, and that is how projects like gaim can be ported.

LinuxWorld News Desk 11/10/05 09:55:49 AM EST

Linux and Microsoft: Getting Started in Linux for the Experienced .NET Developer. 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.

Enterprise Open Source Magazine News Desk 11/10/05 09:00:14 AM EST

Linux and Microsoft: Getting Started in Linux for the Experienced .NET Developer. 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.