devxlogo

The Mono 2.0 Offerings for Debian GNU/Linux.

The Mono 2.0 Offerings for Debian GNU/Linux.

ebian GNU/Linux and Mono are two leaders of open source software. Debian is a Linux distribution with a social contract that places it among the best examples of free and open source software. Mono provides an open source development platform for .NET. So what does Mono have to offer the Debian user who wants to tap .NET?

This article determines how much of the Mono 2.0 (and beyond) platform is available for Debian users by walking through how well the two products play together. It explores the Mono landscape, going over Debian packages and explaining the associate commands and relevant information about up-to-date .NET compatibility.

Mono Breakdown: Virtual Machines and Managed Code

Virtual machines and managed code are old concepts that have been revived in the past ten years or so through Java, with its Java Virtual Machine (JVM) and byte code, and then .NET, with its Common Language Runtime (CLR) and managed code. Managed code doesn’t run directly on the CPU but rather on a virtual machine (VM), and the VM is an intermediate layer between the CPU and its machine code that behaves like a CPU. In effect, the VM replaces the CPU and the byte code replaces the machine code. This approach is used mainly for portability; if all compatibility issues are solved at the VM level, then the byte code programs will run on all platforms where the VM exists. All this also bears advantages in terms of security and memory management.

Programs that run on the .NET CLR are written in a language called Common Intermediate Language (CIL). As the open source implementation of the CLR, the Mono runtime also can run code written in CIL. This opens up all the CPUs and operating systems that Mono runs on to any CIL binary code produced by .NET Visual Studio compilers.

Getting Started with Mono on Debian

To start using Mono, you first install the Mono runtime, which provides the virtual execution environment to run a CIL executable. The first Debian package to install with the apt utility is mono-jit:

apt-get install mono-jit

Under /usr/bin, you now will find a Mono Linux executable that is the interpreter for CIL programs. From here on, the instructions use an “unstable” version of Debian GNU/Linux in order to download and install Mono version 2.0. Unstable is a misleading term, as it refers to a fully functional Debian release with the newest packages.

A .NET executable is an .exe file, but unlike any other .exe file, it cannot be run by itself without a CLR. With Mono, you can run it with this simple command:

mono program_name.exe

Clearly, Mono is not another Windows emulator! It can run only Windows Portable Executable (PE) programs written in CIL and produced by .NET compilers.

Gendarme and Other Mono Tools

Two packages named mono-tools-devel and mono-tools-gui provide a group of useful applications that can help explain how Mono and the CLR platform are structured:

  • mono-tools-devel
    • create-native-map
    • gendarme
  • mono-tools-gui
    • gasnview
    • ilcontrast
    • gui-compare (quite an interesting tool)

Among these tools, gendarme deserves special consideration; it can directly inspect CIL code to discover problems that the compiler cannot identify.

Mono Language Compilers on Debian

Several important options reveal the particularity of the Mono runtime. One aspect to keep in mind is that by default the Mono runtime behaves like a Just-In-Time (JIT) compiler. This means that while it interprets pieces of CIL byte code it also natively compiles and caches the same pieces in machine language. The performance advantages are straightforward. With the –aot option, the Mono runtime also implements Ahead-Of-Time (AOT) compilation, meaning that it produces all the system-dependent binary code before execution. This maximizes performance by paying a little more at the start.

gmcs: Mono C# Compiler

In a managed-code development environment, every available compiler usually produces an executable for the virtual machine. As such, any .NET compiler produces a CIL executable. The compilers output an .EXE or .DLL file. The former program is called process assembly, the latter a library assembly.

If /usr/bin/mono runs CIL programs compiled with Visual Studio .NET, then you can produce CIL programs with Mono itself. The Mono framework offers a plethora of CIL compilers. The C# compiler is the most important because it is the reference for .NET, and like the CLR, it has become an ECMA standard (ECMA-334).

Three Debian packages, each with its command-line compiler, address by default different versions of CLI and C# (see Table 1).

CommandDebian Package(s)C# VersionCLI Version
mcsmono-mcs1.0, 2.0 (partially)1.X
gmcsmono-gmcs2.02.0
smcsmono-smcs3.02.1 (subset of 2.0 plus extensions)
Table 1. Debian Packages to Address by Different Versions of CLI and C#
Figure 1. Assemblies Written in Different Languages Interacting: Here is a schema of how assemblies written in different languages can interact on Mono and .NET.

With regard to smcs, you install a compiler for runtime 2.1 that compiles applications for Moonlight, the open-source clone for Silverlight. Moonlight will be able to run all Silverlight executables, even outside the browser.

The list of additional languages you can program with the Mono platform is very long. All the languages available in Mono are also available in .NET and vice versa, at least in the sense that wherever the source code is compiled, the CIL code produced is “runnable” on the other platforms. As explained before, Mono offers a set of language compilers that produce CIL executables ready to run on Mono or .NET runtimes. However, some .NET compilers currently produce code that doesn’t run on the Mono platform because these compilers don’t compile to pure CIL (for example, the Microsoft Managed C++ compiler).

Table 2 lists the main Mono compilers you can install on Debian, and Figure 1 presents a summarizing schema of how assemblies written in different languages can interact and reuse one other (for example, a class library written in C# can be used by a program in IronPython).

LanguageCommandDebian Package(s)
Visual Basic 2005vbncmono-vbnc
libmono-microsoft-visualbasic8.0-cil
Booboocboo
Nemerlenccnemerle
IronPythonipyironpython
Table 2. Mono Compilers You Can Install on Debian

The Mono Collection of Library Assemblies

This section details the libraries Mono provides for running .NET programs.

Base Class Library (BCL) and Beyond

BCL is the name for a set of DLLs that make up the standard library of the .NET Framework. These library assemblies are available to all languages through a binding mechanism. Mono implements BCL, and you can install it with Debian package libmono-system2.0-cil. This package also installs the Mono Core Library (mscorlib.dll), the glue between BCL, JIT, and Mono Security Library.

Where does Mono search for the library assemblies that a program needs? Firstly, it tries to find them in the current directory and then in the directories assigned to the MONO_PATH environment variable. As a last resort, it turns to Global Access Cache (GAC). Designed to solve the age-old Microsoft problem called “DLL hell,” GAC is the central repository of library assemblies. Among other features, it allows developers to have libraries with the same name but different version numbers. GAC is a tool mainly for developer teams; its main goal is letting users share their assemblies.

GAC introduced and continues to supports the concept of strong names for assemblies. A strong name is made up of the simple filename, version number, what is called culture (optional), and a public key. The Debian package mono-gac installs the gacutil command-line utility, which mimics all the features of the .NET homonym command.

GTK# and Windows Forms

Your Mono program probably will need a GUI, and you need a graphic framework to implement rich and efficient user interfaces. In Mono, you have a number of options but the best one is GTK#, a Mono binding around the GTK+ GUI libraries upon which the GNOME project is based.

In Debian, a metapackage called gtk-sharp2 provides all the packages needed to compile a GTK# program. The /usr/share/gtk-sharp2-examples directory also contains some interesting examples. The Mono for Windows installation setup also will install all GTK# library assemblies for a complete compatibility so your GTK# programs will run in Windows.

Windows Forms

The Mono team removed most of the obstacles that prevented the implementation of .NET Windows Forms library assemblies. You install them with the package libmono-winforms2.0-cil. Just remember to use the -pkg:dotnet option when compiling a Windows Forms program.

Web Development and ASP.NET

With the package libmono-system-web2.0-cil, you can program in ASP.NET. Then you have two choices for running your ASP.NET applications: with Apache, installing mono-server-apache or with a lightweight web server called xsp, installing mono-xsp.

Database Programming

Mono also supports the ADO.NET Framework and its way of connecting to databases. The libmono2.0-cil package provides, among others, the Mono.Data.dll, which offers Provider Factory and Data Tools for Mono ADO.NET. Mono can use the ADO.NET Framework to interact with open source databases, for example MySQL Connector/Net from MySQL AB is the recommended .NET and Mono data provider for MySQL.

Up Next, Mono 2.2 with New C# Features

Mono is always a step behind .NET’s evolution in order to implement the new features; looking into the future of Mono means seeing the present of .NET. The upcoming Mono 2.2 should be released with a lot of enhancements and new modules, for example, the C# shell and Language Integrated Query (LINQ). The C# shell is an interactive shell that reads-evals-prints C# expressions and is built on top of a library assembly that provides a compiler service. LINQ is a new component of C# version 3.0 that basically extends the use of the SQL query syntax and mechanism to any collection of data represented by a class.

Mono is moving to have complete coverage of these new parts, but the relative Debian packages still don’t exist even in Debian’s unstable pool. If you want a cutting edge version of Mono, you will have to download the daily tarball and then compile it as follows:

cd /usr/localwget -c http://mono.ximian.com/daily/mono-latest.tar.gztar -xvjf mono-latest.tar.gz./configure –prefix=/optmake

Have a coffee, and then enter:

make install

The steps above will install a Mono 2.2 Beta release under the /opt directory. In order to use it instead of the Mono 2.0 official release already installed with the apt tool, you will have to accordingly set PATH environment variable by adding the /opt/bin directory before the official /usr/bin.

Now you can run the C# interactive shell with the csharp command, and you will get the interactive prompt csharp> meaning you are ready to read-eval-print C# statements. Here is a simple example taken from the Mono project that shows how this works and what LINQ means:

csharp> var last_week = DateTime.Now – TimeSpan.FromDays (7);csharp> from f in Directory.GetFiles ("/etc")      >    let fi = new FileInfo (f)      >    where fi.LastWriteTime < last_week      >    select f;{ "/etc/adjtime", "/etc/asound.state", "/etc/ld.so.cache",  "/etc/mtab", "/etc/printcap", "/etc/resolv.conf" }

This little piece of code shows the files under the /etc directory, which was recently modified. The csharp command could be very useful when you debug single lines of code, and LINQ allows you to exploit the power of SQL in C#.

MoMA, Not the Museum

The Mono Migration Analyzer (MoMA) is a Mono process assembly that analyzes which .NET API people are using in .NET programs and helps determine the runnability of the same API under Mono. Mono could fail to run a .NET program for a number of reasons (for example, if a .NET program calls Platform Invocation Services or P/Invoke). MoMA will indicate whether a program uses P/Invoke or a .NET API not yet supported by Mono. MoMA doesn’t exist in the unstable Debian package pool because it is a typical Mono/CLI program that you can unzip under a directory and then run with the Mono runtime.

What About the IDE?

Of course, the Mono framework couldn’t come without a decent IDE. Install the monodevelop package and you will have a mature development environment with all the typical features of a modern IDE. In addition to typical instruments such as code completion, class management, and online help, monodevelop also offers an add-in engine for inserting language- or application-specific modules. For instance, if you want to write a macro for OpenOffice with Mono, install cli-uno-bridge and the OpenOffice Automation Samples add-in on monodevelop and learn via the examples.

If you’re a the Debian user who wants to run .NET applications, this article should have given you an idea of what Mono in general and Mono 2.0 in particular has to offer, both today an in the near future. Now it is up to you to further explore the Mono landscape for the most up-to-date .NET compatibility.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist