ike the freely downloadable Microsoft .NET Framework 2.0 SDK, the free open source Mono platform provides a number of command line utilities used to compile .NET source code and manipulate the resulting assembly such as to assign a strong name, deploy the image to the Global Assembly Cache (GAC), view type metadata, etc. Many of the Mono tools even have the same name as their Microsoft counterparts and offer similar functionality. Table 1 provides a Mono-to-Microsoft .NET comparison of some common command-line development tools.
Author’s Note: This article assumes a basic understanding of the Mono platform, the C# programming language and the mechanics of the .NET framework. If you are new to Mono development, I’d suggest reading the article An Introduction to Mono Development before proceeding. |
Table 1. The table shows common Mono vs. Microsoft .NET command line development tools.
Mono Command Line Tool | Microsoft .NET Command Line Tool | Meaning in Life |
al | al | The assembly linker utility is used to manipulate assembly manifests and build multifile assemblies (among other activities). |
mcs/gmcs | csc | The C# language compiler. |
mbas | vbc | The Visual Basic language compiler. |
gacutil | gacutil | Used to interact with the GAC. |
mono (when specifying the -aot command option) | ngen | Performs a pre-compilation of an assembly’s CIL code. |
wsdl | wsdl | Generates client side proxy code for an XML Web services. |
disco | disco | Discovers the URLs of XML Web services located on a Web server. |
xsd | xsd | Generates type definitions from an XSD schema file. |
sn | sn | Used to generate key data for a strongly named assembly. |
monodis | ildasm | The CIL disassembler. |
ilasm | ilasm | The CIL assembler. |
xsp2 | webdev.webserver | A testing and development web server for ASP.NET 2.0 applications. |
While it is certainly true that you can make use of the Mono command line tools and your text editor of choice to build any sort of .NET application, raw command line tools offer little by way of developer productivity. But if you’ve always believed you’d have to give up the comforts of an IDE to develop for Mono, think again. This article provides a high-level survey of three Integrated Development Environments (IDEs) that can facilitate the construction of Mono applications. As you can gather from Table 2, some of these tools are open source. Each targets a particular set of Mono-aware operating systems.
Table 2. Here’s a sampling of Mono-aware IDEs.
Mono-aware IDE | Runs on Windows? | Runs on Unix Linux? | Runs on Mac OS X? | Open Source? |
SharpDevelop | Yes | No | No | Yes |
MonoDevelop | See below | Yes | Yes | Yes |
X-Develop | Yes | Yes | Yes | No |
Author’s Note: Technically it is possible to install MonoDevelop on Windows using the cygwin Unix-emulation environment; however I won’t examine this topic here. |
The purpose of this article is not to provide details regarding every option or feature provided by each IDE (menu choices, use of the visual designers, building custom code snippets, etc), but rather to show you the core details required to compile C# code against the Mono base class libraries and run the assembly under the Mono runtime.
Building Mono Applications using SharpDevelop
SharpDevelop (also known as #develop) is a free, open source IDE for .NET development that runs on Windows. Despite being completely free, this tool has a very compelling set of features, including:
- Support for Microsoft .NET and Mono language compilers
- Visual designer support for Windows Forms applications
- Support for the forthcoming (at the time of this article) Windows Presentation Foundation UI toolkit
- Integration with several popular open source .NET development tools (nant, ndoc, nunit, etc)
- IntelliSense, code completion and code snippet technologies
![]() | |
Figure 1. SharpDevelop Support: SharpDevelop supports Mono-specific projects including Glade# and Gtk# graphical UI applications. |
You can download this IDE (which happens to be written in C#) in source code form or as an installable binary from the SharpDevelop home page. After installing SharpDevelop, launch it and proceed to the File | New | Solution menu option. Notice in Figure 1 that SharpDevelop supports various Mono-specific projects (specifically, Glade# and Gtk# graphical user interface applications).
In addition to these Mono-specific project types, you may select additional project types as well (console apps, Windows Forms apps, class libraries, etc) by accessing a given project from your preferred language node (see the TreeView in Figure 1), which for this article I will assume is C#.
However, by default, SharpDevelop compiles and executes project types you select that are located outside the Mono folder using the Microsoft .NET Framework. To change that default, you must take some deliberate steps after creating the new project type, as discussed in the next several sections.
Creating a Simple Test Application
Because this article is concerned with configuring IDEs to build Mono software rather than the details of C# or the mechanics of the .NET platform, I’ll use a simple application to discuss Mono-specific concerns. To begin, create a new Windows Forms application named SharpDevApp (see Figure 2).
![]() | |
Figure 2. Building Windows Forms Projects: You can use Mono to build a Windows Forms application. |
First, specify that you are using the System.Reflection namespace by adding the following using statement at the top of your initial *.cs file:
using System.Reflection;
As you would hope, SharpDevelop provides an integrated Windows Forms designer which is more or less identical to the designer provided by Microsoft Visual Studio 2003/2005. Switch to the form’s designer (by clicking on the Design tab at the bottom of the code file) and open the Toolbox using the View | Tools menu.
Click on the Windows Forms section of this toolbox, drag a Button control onto the form designer surface, and rename it to btnShowStats using the Properties window. Now, handle the button’s Click event by double clicking the button you placed on the form designer. Finally, implement the Click event hander as shown below:
void BtnShowStatsClick(object sender, System.EventArgs e) { // Get OS hosting this app. string randomStats = string.Format("OS: {0}", Environment.OSVersion.Platform.ToString()); randomStats += Environment.NewLine; // Get path for each assembly used by this application domain. Assembly[] loadedAsms = AppDomain.CurrentDomain.GetAssemblies(); foreach(Assembly asm in loadedAsms) { randomStats += asm.Location; randomStats += Environment.NewLine; } // Now plug info into a message box. MessageBox.Show(randomStats, "Some Random Info..."); }
![]() | |
Figure 3. Default Runtime: By default, SharpDevelop executes assemblies with Microsoft’s .NET implementation. |
Depending on your current background, you may already know that an application domain is the ultimate host of .NET executable as well as each required external code library (e.g., mscorlib.dll, System.Windows.Forms.dll, and so forth). Here, the implementation of the button’s Click event will display the platform OS executing the application, as well as the location of each assembly loaded into the application domain hosting your executable.
Author’s Note: The Environment.NewLine property is quite helpful, because it resolves to “ ” on a Windows operating system or “ ” on Unix-based platforms (including Mac OS X), making your code more portable. |
Now, compile and run your application via the Debug | Run without Debugger menu option. Once you click the button, notice that this application has loaded external assemblies from the Microsoft .NET GAC, which is located under the %windir%Assembly subdirectory (see Figure 3).
Configuring the Mono Compiler
As you have just observed, any non-Mono specific SharpDevelop project will compile your C# code files under the latest build of Microsoft’s .NET platform. To compile under the Mono platform, to open your project’s properties page via the Project | Project options menu and click on the Compiling tab. At this point, select the version of Mono you wish to compile under via the Target Framework dropdown list (see Figure 4).
Author’s Note: If you select Mono 1.1, SharpDevelop uses the mcs compiler to compile your C# files and will reference the Mono 1.1 base class libraries. Selecting Mono 2.0 will instead make use of gmcs and the Mono 2.0 base class libraries. See An Introduction to Mono Development for further details. |
|
|
For the curious, when you change the Target Framework setting, you are in fact updating the
Running Under the Mono Runtime Environment
Even though you have now instructed SharpDevelop to compile your code using the Mono C# compiler, your application will still load into the Microsoft .NET runtime and obtain external assemblies from the Microsoft .NET GAC. To load your assemblies under the Mono runtime and obtain assemblies from the Mono GAC you must specify mono.exe as the Start Action, via the Debug tab of your project’s properties page.
To do that, select the Debug tab, click on the “Start external program” radio button, and navigate to the path of the mono.exe utility (which you’ll find by default in C:Program FilesMono-
Next, you will need to provide the current location of the compiled assembly as a parameter to the Mono runtime. To do so, specify “${TargetPath}” (with quotations, to account for a path containing blank spaces) as a value to the Command line arguments text box. Figure 6 shows the final setting within the Debug tab.
|
|
|
Now, if you compile and run your application using the Debug | Run without debugger menu option, you’ll see the message box in Figure 7 when you click the Form’s Button.
Notice that the application now loads external assemblies from the Mono GAC (located by default under the libmonogac subdirectory of your Mono installation).
Author’s Note: Using the current version of SharpDevelop, it’s not possible to debug your code base when running under the Mono runtime. Therefore, any break points you have set will be ignored. |
Referencing Assemblies from the Mono GAC
To wrap up this look at SharpDevelop, it is important to know that when you are building .NET applications targeting Mono, the IDE makes it very simple to reference assemblies deployed to the Mono GAC (or the Microsoft GAC for that matter). Simply right click on the References folder within the Project window and select “Add Mono Reference” (see Figure 8).
Building Mono Applications using MonoDevelop
MonoDevelop is an IDE based on the SharpDevelop code base. However, unlike SharpDevelop, MonoDevelop was not constructed using the Windows Forms user interface toolkit?it uses Gtk# instead. As you may know, Gtk# is a managed implementation of a desktop API named “Gtk+,” which is quite well-known within the Unix / Linux development community. Like SharpDevelop, MonoDevelop has an impressive feature set, including:
- Support for multiple .NET programming languages
- Visual designers for Gtk# GUI applications
- The ability to import existing Microsoft Visual Studio projects
- Integration with several popular open source .NET development tools (nant, ndoc, nunit, etc)
- IntelliSense, code completion and code snippet technologies
While Gtk# itself is a platform-independent API, MonoDevelop is targeted toward people developing Mono applications on Unix/Linux distributions, given the large number of dependencies required to compile Gtk# and MonoDevelop from source. However, given that the Macintosh OS is itself Unix-based, it is possible to install this particular IDE on Mac OS X.
To do so you must install the X-Windows package as well as a slew of additional dependencies that aren’t on the Mac OS X installation media. This article will not cover the (numerous) steps necessary to get MonoDevelop up and running on the Mac, however you can find detailed instructions at the MonoDevelop Web site. (A word of advice: be sure to have plenty of coffee on hand for your upcoming all night project!)
Thankfully, the Mono Linux installation package installs MonoDevelop automatically. After installing the package, you launch MonoDevelop by clicking on the MonoDevelop icon in your installation folder. After launching the IDE, you are can create a new project via the File | New project menu option.
As you would expect, you have a choice of numerous project types. Currently however, MonoDevelop does not have a native Windows Forms project template; therefore, to compile the code created from the previous SharpDevApp project, create a new empty C# project named MonoDevApp (see Figure 9).
|
|
Now, open the Solution window (via the View menu), right click on the project icon and select the Options menu. From here, ensure you are compiling under Mono 2.0 (see Figure 10).
To import your existing *.cs files into this new MonoDevelop project, right click on your project name within the Solution window and select Add | Add Files. From here, select your MainForm.cs and MainForm.Designer.cs files. Finally, right click on the References folder and add references to System.Windows.Forms.dll, System.Drawing.dll, System.dll and mscorlib.dll assemblies via the Edit References dialog box (see Figure 11).
|
|
|
After finishing these tasks, your Solution window should look like Figure 12.
At this point you can compile and run your application using the Run | Run menu option. This time, when you click the button, you’ll see that you are indeed running under a Unix-based OS and are referencing assemblies form the Mono GAC (see Figure 13).
That should be enough information regarding MonoDevelop to whet your appetite. If you are interested in additional details, be sure to check out the official MonoDevelop Web site.
Building Mono Applications using X-Develop
The final IDE I’ll discuss is X-Develop. While this IDE is not free, you can download a 20-day evaluation copy from the Omnicore software Web site. If you decide to purchase a full copy of this IDE, the going price is currently $149 USD for a single-user license.
Author’s Note: It is my experience that X-Develop is currently the best approach for building Mono applications on Mac OS X, and well worth the asking price. |
Perhaps the major advantage of this particular product is that you can install it on both Windows and Mac OS X as well as on numerous Linux distributions. Beyond this key benefit, X-Develop supports a number of bells and whistles not supported by SharpDevelop or MonoDevelop, for example:
- Support for Microsoft .NET, Mono and Java development
- Numerous Windows Forms and Gtk# visual designer tools
- Integrated support for code refactoring and code metrics
I won’t walk through the process of building a complete application using this tool, but for comparison purposes, the process begins similarly to others by creating a new solution using the Solution | New Solution dialog (see Figure 14).
|
|
After creating the project, you may then select the Mono runtime version you wish to compile against using the Solution | .NET Framework menu option. You can add assembly references using the Solution Project Properties menu option. Figure 15 showcases the overall look and feel of X-Develop.
That wraps up this examination of three Mono-aware IDEs. Hopefully you are now convinced that you can happily build Mono-base software decoupled from the command shell. While it is true that a solid knowledge of the command line development tools is a very important aspect of working with the Mono platform, nothing beats the rapid application development provided by a full featured GUI programming environment.