How to port existing asp.net MVC 3 application from windows to Linux
Author: Veeresh Rudrappa. Date: March 13, 2013
When I set out to port .NET application from windows 7 to Linux, I thought its going to be a long
laborious process with lots of configurations. But surprisingly it did not take much time. Most of you
might have already heard about mono-project, an open source implementation of the Microsoft .NET Framework.
It is aimed at helping developers develop cross-platform applications. Yes, like the java, with write once run anywhere ideology.
I must say, in whatever I have tried till now, it does a very good job at it. I had been hearing about MONO from quite some time , but never set out to experiment with it. I'll show here in this blog, how I managed to port my application onto Linux.
I will port the same application that I used for explaining my previous blogs Setup NHibernate with PostgreSQL in ASP.NET and Using NHibernate with PostgreSql in ASP.NET MVC. I'm running Ubuntu 12.04 on Oracle Virtual box and will be porting the application on that.
Step 1: Firstly let us install the MONO .NET framework on Ubuntu 12.04. Execute the following commands on your terminal.
a.sudo apt-get update. It will get you the latest packages.
b.sudo apt-get install mono-complete
c.sudo apt-get install monodevelop. MonoDevelop is an IDE just like MS Visual Studio.
d.sudo apt-get install mono-xsp2
e.sudo apt-get install mono-xsp4
Step 2: Now let us test if Mono .NET framework is installed properly. Create a simple aspx page on your Desktop or any folder in Ubuntu. Navigate to the same folder in your terminal. Execute xsp4. In doing so you would be starting a server listening on port 8080. Now open your browser and type http://localhost/8080:hello.aspx . You should see the contents of your aspx page displayed.
Step 3: Now we are all set to port our application. Copy the Project folder of your ASP.NET MVC 3 Application from windows onto Ubuntu. You would also need to copy the following DLL's from your windows.
1. System.Web.Mvc.dll. Located at C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies.
2. System.Web.Entity.dll. Located at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
3. System.Web.Helpers.dll. Located at C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies.
4. System.Web.WebPages.dll. Located at C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies.
5. System.Web.WebPages.Razor.dll. Located at C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies.
Step 4: In your Ubuntu terminal open the monodevelop IDE. Go to File menu and click on Open New solution file, in my case NHibernateTest.sln.
Once the project gets loaded, all those DLL's mentioned above would be highlighted in red because its location has been changed and its no more accessible from its original location. Also Iesi.Collections and NHibernate.dll had missing references on my project.
Delete all the Red highlighted one's from your existing references and we can add them back with the correct location. Right click on your References > Edit Reference and add NHibernate.dll and Iesi.Collections which should be in the bin folder of the project.
Also add the remaining 5 System.Web references mentioned above.

Step 5: Finally, lets update the Database server address. You can either setup the entire Database on the Linux machine or just connect to an existing one over the network.
Look at my earlier blog on How to connect to postgreSql over the network. Update the Database connection string with the correct database server address.
I'm assuming that you already have setup your network connection properly in Oracle Virtual Box. If its been setup properly then you should be able to "ping" from Linux terminal to windows command prompt.
If you are connecting to a wireless network then it could be little tricky to set up bridged network adapter between virtual box Linux machine and windows. Its easy if you connect via Ethernet cable and
select your network adapter as "Bridged Adapter" in virtual box settings.
Now press ctrl+F5 or click on Run from the menu. At this point, I got an Application error saying "No access to the given key".
Go to bin folder of your project and delete Microsoft.Web.Infrastructure.dll. We will let our Application use the MONO version instead.
Now run your project again and it should work. :)

It wasn't that hard, was it. In the coming days I will experiment more with mono framework and maybe blog on it if I come up with something substantial.