RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Mono IDEs: Going Beyond the Command Line : Page 2

Choosing to develop for Mono no longer means that you're also have to throw away the advantages that integrated IDEs provide. Instead, you have a wide—and growing—range of Mono IDE options.

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}",
     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 "\r\n" on a Windows operating system or "\n" 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).

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date