Update Jan 2014: Go straight to github for MVC Templates for .Net 4 and .Net 4.5 or see asp-net-mvc4-net-framework-version-4-5-c-razor-template-for-mono-on-mac-and-linux for more recent notes.
I’ve been trying for a while to get this working. It all seemed so-near-and-yet-so-far. But here is the Visual Studio 2010 C# Asp.Net MVC4 Template Project which works on my Mac and (thanks to comment from Stephen) on Linux :
Visual Studio 2010 Asp.Net Mvc4 CS# Web Application Template modified for Mono
There’s a list of issues which frustrated earlier attempts but the above link is to a project that does build and run on my Mac. Things to make it work included:
- Got the latest Xamarin Studio, previously known as MonoDevelop
- Mono version: I got MVC4 on Framework version 4 running on Mono 2.10.12; and MVC4 on Framework 4.5 on Mono 3.2.5. Nb I’m not sure whether everything related to async is currently working, but many web apps wouldn’t want to use async.
- There’s a list of potential issues to address described in this stackoverflow post, I think what I did was just:
- Delete Microsoft.Web.Infrastructure.dll from the bin directory
- I also removed Entity Framework References. As of Jan 2014 that’s not yet done on the Mono, although this may change shortly.
- At first I commented out the line
global.asax.cs Application_Startbecause it caused an error which appeared to refer to Entity Framework but that might just have been because I had removed System.Web.DynamicData too, so I put DynamicData back in.
- The StyleBundles failed with a typo, or rather a case-sensitivity issue. A lot of .Net code is written on the assumption of a case-insensitive file system, but mono on *nix will usually have a case-sensitive filesystem, so you have to start being pedantic about getting the case correct. For instance
App_Start/BundleConfig.csreferred to the file
site.css, so it wasn’t found until I corrected it.
- Having taking the ‘intranet’ template which uses Windows authentication, I changed the
<allow users="?"></allow>. But this gives you no security. The simplest route back to a secure website is to instead put in forms authentication, I don’t yet have a solution for windows authentication on mono.
- I included all the nugetted package dlls in the zipfile, except that I deleted the EntityFramework stuff.
Kudos to all who worked so hard to make MVC4 on Mono possible. And of course to those who made MVC4 possible at all.