This post describes how to build and run ASP.NET MVC4 applications using Mono, xbuild, nuget and xsp4.
Following on from my post about building servicestack apps with Mono and friends, I wanted to get ASP.NET MVC apps up and running with Mono and xbuild too.
I ended up doing it with MVC4, as with MVC4 all the MVC-related libraries can be pulled in via Nuget.
I went down the route of compiling Mono 3. I’m not entirely sure if MVC4 works with 2.10.8, which is the version in most package repositories at the moment. I know for a fact it works with 3.0.10, as this is the version I built!
Compiling Mono 3
I followed this excellent post for compiling Mono and libgdiplus and xsp4. It all went fairly smoothly, other than the gotcha with libgdiplus as mentioned in my previous post.
Setting up a test project
erikd also handily provides a test MVC4 project, as bundled up from an empty VS2012 MVC4 project. It’s linked to in his post.
Like with servicestack, I’m hoping to set up a bootstrappable project template for MVC4 on github when I get chance.
Setting up Nuget package restore
Where I had to branch out from erik’s post is for actually building the project. erik doesn’t mention how he’s doing this, but I’m guessing that it might be with MonoDevelop or Xamarin Studio, which probably just works. I’m using xbuild from the command-line however, so there’s a bit more extra setup I had to do.
The project already has packages.config for the required libs, and the solution has the required .nuget folder. However we need to tweak the Nuget.targets file as I mentioned in my earlier post.
Add a RestorePackages tag and an import to NuGet.targets using the following:
1 2 3 4
(See this post and comment).
I also found that I needed to remove a trailing space in the RestoreCommand setting in NuGet.targets:
Something I forgot to mention in the previous post, before you build you need to do:
It’s worth putting that in your shell startup script if you’re doing a lot of work with Mono.
I also did:
for good luck (and to resolve a build warning).
Then build with
It should pull in all the required packages and build.
Then simply switch into the project directory and run xsp4.
localhost:8080 and you should see your brand
new MVC4 site!