Open Source .NET: Platform-Independent .NET Application Development with MONO – part one
Abstract
Over the years, the Linux operating system has become more popular among the developer community due to a significant cost advantage over proprietary platforms. The present problem with .NET centric applications is that they typically don't run on Non-Microsoft operating systems such as UNIX, Mac and various Linux distributions. To overcome such limitations, Microsoft created the Mono project. This enables you to leverage .NET application and Visual Studio skills in Non-Microsoft Operating systems. This article introduces you the cross-platform C# and .NET development using an open source implementation of .NET using Mono.
Prerequisite
First, you need to configure your workstation for Mono centric application development. To do so, download and install the following software
Become a certified reverse engineer!
- Mono 2.10.x GTK for .NET (www.go-mono.com)
- Mono tools
- MonoDevelop IDE (Xamarin Studio)
- One of the following Operating Systems (Windows 7, 8 ,2008 server, Vista)
- Mono server (optional)
- VMware or Virtual PC
- Either OS in VMware OS – [OpenSUSE, Linux, Fedora ,Mac]
- SQL Server 2008 (optional)
Mono
Mono platform is an open-source implementation of Microsoft that allows the developer to execute .NET centric applications on other platforms such Mac or Linux. Using such open source implementations of .NET, you can create, compile, and execute .NET assemblies on operating systems other than the Microsoft platform.
Surprisingly, Mono also provides an installation package for Windows operating systems. Thus, it is possible to build and execute .NET assemblies on Windows without ever installing the Visual studio IDE or .NET Framework SDK. Hence, under Mono, you can build real time, production-ready assemblies that use Windows Forms, LINQ, XML web services, ADO.NET and ASP.NET by taking an advantage of existing core CLR namespaces.
The .NET cross-platform interoperability capabilities implementation approaches are different. Unlike java, Microsoft doesn't provide .NET installer for Mac and other Linux operating systems. Microsoft has documented the formal specifications (referred to as CLI implementations) of interoperability so that other operating systems distributions can use them as a roadmap for .NET application building on various platforms.
At present, Mono is compatible with the .NET 2.0, C# 2008 and later, which implies you can build Windows Forms Applications, ASP.NET website. Mono applications are currently unable to uses WCF, WPF, WWF APIs. In addition, Mono also provides an open source distribution of Silverlight API named Moonlight. The browser runs under Linux can host and run Silverlight web applications.
The final point of interest about the Mono features sets is that it supports numerous programming languages' compilers as follows:
Mono Workstation Installation
Go to the Mono website www.go-mono.com and locate the download tab. Here, you can download a variety of installers for specific platform such as Windows, Mac, and Linux. This article is talking about the open source nature of .NET so we choose Windows platform and select Gtk# for .NET as follows:
Once you finish with the setup program, by default Mono is installed under Program FilesMono-version. You run the vast variety of Mono development tools from command line. To test whether the Mono is installed properly or not, just run the following command in the in-built command prompt of Mono as:
When you install Mono, you will not be provided the GUI to test the application code. However, this doesn't mean that you can't build or test your applications from command prompt because alike .NET framework various tools such csc.exe or vbc.exe. We can still test the mono applications with its in-built command prompt. But programmer considers it very complicated to test the application via command prompt, so we can download the Mono Developer IDE such as Xamarin Studio to ease the way of developer.
After installing the Xamarin Studio IDE, it will look alike Visual Studio IDE where we can develop variety of solutions, such as ASP.NET, console based and Android apps by choosing C# or VB.net languages.
Mono Tools
Mono ships with various development tools that are functionally equivalent to .NET SDK tools. The following table lists the associated tools, such as:
Building .NET Console Application in Mono
The infrastructure of the Mono console application is similar to the traditional C#.NET console application .To develop first Mono based console application with Xamarin Studio, follow these steps.
- Open Xamarin studio from Start Menu.
-
Go to File -> New -> Solution. Here choose the Console Application in C# language. Select the solution Directory and finally assign a project name as TestConsoleApp.
-
After that, you will found the following working area with entire solution directories as:
- Now put the following code in the Main.cs file as:[c language="sharp"]
using System;namespace TestConsoleApp
{
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine ("Welcome! First Program");
Console.ReadKey ();
}
}
}
[/c] - Finally Build the project using F8, and Run it with F5 to see the output.
- You can also build and debug this solution from Mono command prompt rather than its GUI.
-
In this regard open the notepad and put this code to create a *.rsp file as;
[plain]
/target:exe
/out:TestConsoleApp.exe
main.cs
[/plain] - Save this into the solution directory with name TestBuild.rsp and open the Mono Command Prompt.
-
Navigate to solution TestConsoleApp folder where the *.rsp file is resided. And compile this solution using the mcs.exe @TestBuild.rsp command;
- If the solution is compiled successfully, a TestConsoleApp.exe file is created.
-
At this point, you can load the TestConsoleApp.exe into the Mono runtime engine by specifying the name of executable as an argument to Mono as:
[plain]
Mono TestConsoleApp.exe
[/plain] -
You can also view the assembly manifest using monodis.exe as:
To run an application under Mono, you must pass it into the Mono Runtime through Mono.exe utility. If you do not, you will be loading your assembly into Microsoft CLR.
Test the Platform Independence Nature under Linux Environment
So far, this article has shown us how to create assemblies that you could also have compiled using the Microsoft .NET Framework SDK. The real motive behind this article is to execute the applications which are developed under .NET CLR. However, Here we configure the mono software framework over an open source Linux distribution operating system backtrack to execute .NET application. So, first download the Mono binaries using the wget utility and execute these series of commands to configure it properly as:
[plain]
mkdir ajay
cd ajay
wget --no-check-certificate https://raw.github.com/nathanb/iws- snippets/master/mono-install-scripts/ubuntu/install_mono-3.0.sh
chmod 755 install_mono-3.0.sh
./install_mono-3.0.sh
Such commands probably would take some time to configure fully mono. After that, you can ensure the mono software installation via this command as:
Now, export the previously created .NET assembly TestConsoleApp.exe to backtrack by FTP, Telnet or other ways. Finally execute the .NET assembly using the Mono utility as follows:
The above figure shows the exact Console output running under open source Linux distribution OS backtrack.
Reference
- www.go-mono.com
- ECMA-34: Defines the syntax of the C# programming language.
- ECMA-335: Common Language Infrastructure specification.
Conclusion
Become a certified reverse engineer!
The point of this article was to give an introduction to the cross-platform nature of C# programming language and .NET platform when using the Mono framework. In case you need to build .NET application that can execute under a variety of operating systems such as Linux, Fedora, Backtrack and openSUSE, the Mono project is a wonderful choice for doing so.