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).

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

David,

I agree with you completely. WinForms is the key.

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

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.

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.

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.


  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
SYS-CON Events announced today that Yahoo!, a leading global Internet brand and one of the most traf...
With an ever-increasing number of companies now buying computing, storage, and networking power as t...
Yahoo! is investing significantly in Cloud Computing to support the company's global applications an...
SYS-CON Events announced today the latest event in its innovative series of real-world technology co...
ESRI, the leader in geographic information system (GIS) technology, was selected as one of two final...
Aster is seeking to level the playing field on the data warehousing entry front, and that message sh...
"What's fueling the interest in RIA?" asked Regev Yativ, President & CEO of Magic Software Enterpris...
The concept was very well received by non-developer IT Pro's and developers that are experts in othe...
Why are we so confident about the first point? Because IMAP support in WebMail Pro now includes quot...
Business users already heavily rely on their BlackBerry smartphones for telephone and wireless email...
Mimosa Systems, a provider of next-generation email, file and SharePoint archiving solutions, today ...
Businesses need the latest technologies to help them meet their needs, support their goals and compe...
F5 Networks, Inc., a provider Application Delivery Networking (ADN), has announced integration betwe...
Comodo's free pc security software, Comodo Internet Security, has earned five stars, the maximum num...
Oracle has announced the general availability of Oracle Service-Oriented Architecture (SOA) Suite 11...
As part of today's Oracle(R) Fusion Middleware 11g launch, Oracle announced that Oracle Fusion Middl...
With the advent of Cloud Computing, the cost of computation, application hosting and content storage...
Virtualization, viewed as one of the most promising technology investments in an economic downturn, ...
Red Hat, Inc., has announced the Premier Cloud Provider Certification and Partner Program, designed ...
“SOA serves as the foundation for the move into the cloud,” stated Dr. Kareem Yusuf, Director Produc...