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

Command Debian Package(s) C# Version CLI Version
mcs mono-mcs 1.0, 2.0 (partially) 1.X
gmcs mono-gmcs 2.0 2.0
smcs mono-smcs 3.0 2.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).

Language Command Debian Package(s)
Visual Basic 2005 vbnc mono-vbnc
libmono-microsoft-visualbasic8.0-cil
Boo booc boo
Nemerle ncc nemerle
IronPython ipy ironpython
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.

devx-admin

devx-admin

Share the Post:
USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India,

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor

USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies in the USA. Through a

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted