Since the recent release of Ubuntu 14.04 I was surprised to see a new version of MonoDevelop, so I wanted to try creating an ASP.NET MVC 3 (Razor) project but it failed and threw the following exception:

System.IO.FileNotFoundException:Could not find file "/usr/lib/monodevelop/AddIns/MonoDevelop.AspNet.Mvc/Templates/Common/Index.cshtml".File name:'/usr/lib/monodevelop/AddIns/MonoDevelop.AspNet.Mvc/Templates/Common/Index.cshtml'

So while searching on the Internet for hours I found the following solution and hope this will solve your problem too.

Download and Build MonoDevelop

First remove MonoDevelop from Ubuntu:

sudo apt-get remove monodevelop

Before you can build you will need to following components installed:

sudo apt-get install git automake gtk-sharp2 gnome-sharp2 mono-xsp4

Clone the latest source code from GitHub, build and install it:

git clone https://github.com/mono/monodevelop.git
cd monodevelop
./configure --profile=stable
sudo make
sudo make install

Create and set permission to the following directory for mono:

sudo mkdir /etc/mono/registry
sudo mkdir /etc/mono/registry/LocalMachine
sudo chmod g+rwx /etc/mono/registry
sudo chmod g+rwx /etc/mono/registry/LocalMachine

Create an ASP.NET MVC 3 (Razor) Project

Run MonoDevelop and create a new ASP.NET MVC 3 (Razor) project and then change the default .NET Framework 4.0 to 4.5 in your project’s options under General.

Screenshot from 2014-06-27 21:57:19

And now remove the following broken references in your project’s reference folder in red (System.Web.Helpers and System.Web.WebPages):

Screenshot from 2014-06-27 21:59:28

Now to fix those references that we just delete you will need to go to Nuget and install the Microsoft ASP.NET Web Pages package:

Screenshot from 2014-06-27 21:40:54

Now go to your project’s Web.config file and remove or comment out the following line in the <appSettings>:

<add key="webpages:Version" value="1.0.0.0" />

Open the Global.asax.cs file and make sure the following references are added:

using System.Web.Mvc;
using System.Web.Routing;
using System.Web.WebPages.Scope;
using System.Reflection;

Now add the Application_BeginRequest() method to the MvcApplication class in the Global.asax.cs file:

protected void Application_BeginRequest()
{
    var ob = typeof(AspNetRequestScopeStorageProvider).Assembly.GetType("System.Web.WebPages.WebPageHttpModule").GetProperty("AppStartExecuteCompleted",BindingFlags.NonPublic | BindingFlags.Static);
    ob.SetValue(null, true, null);
}

Now you should be able to press F5 to run and see the following message on the page.

Welcome to ASP.NET MVC on Mono!

I hope this information is useful to everyone please leave a comment if any of the instructions don’t work for you and I will do my best to help you out.

Shares