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


Mono IDEs: Going Beyond the Command Line : Page 3

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.

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.

Figure 4. Compiling under Mono 2.0: In SharpDevelop, select the target framework version from the Project Options dialog on the "Compiling" tab.
Figure 5. The <TargetFrameworkVersion> Element. Change this setting to select the framework version you want to target.
For the curious, when you change the Target Framework setting, you are in fact updating the <TargetFrameworkVersion> value of your *.csproj file (see Figure 5).

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 Files\Mono-<version>\bin; where <version> is the current version of Mono installed on your workstation).

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.

Figure 6. Running Under Mono: To make your assemblies run under Mono and use the Mono GAC, you must provide the path to the Mono runtime (mono.exe) in the Debug tab of the SharpDevelop IDE.
Figure 7. Executing under Mono: The dialog shows the paths to the various assemblies used by the sample application in the Mono GAC.
Figure 8. Referencing Assemblies Deployed to the Mono GAC: To add a Mono reference, right click on the References folder and select "Add Mono Reference."
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 \lib\mono\gac 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).

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