I got around to setting up a template solution for ASP.NET MVC4 for Mono on github. You can use this to bootstrap new MVC4 Mono projects (using the unfortunately named strapping-young-lad bootstrapper.)
This setup gives you a way to quickly get going with a new MVC4 project that builds and runs with Mono and XSP4. It’s kind of like doing a file new empty MVC project in Visual Studio.
My primary use case so far is so I can quickly answer MVC questions on stackoverflow without having to reboot into Windows, but hopefully other uses will become apparent…
strapping young lad
strapping-young-lad, which I will henceforth refer to as just lad to avoid any further embarrassment, is a project bootstrapper. It’s based on warmuP, which is great but only works on Windows. (I think. To be more accurate — I struggled a little getting it to work with Mono, so I just opted to use lad instead.)
What lad does is:
- grab a git repository (can be local or somewhere remote like github)
- replace all instances of certain tokens in that repository with a given replacement
So say I have a file named __NAME__.sln in my repository, and I run
I’ll get a new folder with the file FunkyMonkey.sln in it. Token replacement also works inside files.
The first place I personally saw solution generation being used (via warmup in this case) was in Amir Rajan’s cool Oak project. It’s a great idea.
There’s installation instructions at lad’s repo.
On Ubuntu I just did
A couple of fixes
I had to fix up a couple of things in order to get lad to work properly for me.
First off, in
lad.rb, I had to change the command for
moving the project files from their temporary location to their
1 2 3
1 2 3
File.rename version doesn’t seem to work when
moving files across partitions, and as my /home folder
is on a separate partition this step was failing.
Second up, the command for replacing the tokens inside files wasn’t working in some cases. I’m not entirely sure why. I noticed it on packages.config and Web.config, which after the token replacement step end up as empty files. These are both xml, which could have something to do with it – but the token replacement worked fine on the csproj file, which is also xml, so I’m not really sure.
Anyway, the following change is made to line 22 of
You can make these changes directly to the gem’s files, in
I’m going to put in a pull request to the lad project for these changes, so hopefully they’ll be incorporated soon and you won’t need to make these manual changes.
So once lad is fixed, we can run it and pull down our solution template and switch all instances of __NAME__ to our new project name.
The template project that I set up is located at:
This template has the various bits and pieces needed to get the NuGet restore to work, as described in my previous post, and a suitably configured packages.config.
As per that post, for this template to work you’ll need to build Mono 3.0.10 and xsp4, and you’ll still need to do the export of EnableNuGetPackageRestore.
Ok, so the command to run lad is:
This will set up a new directory with a solution named HelloMvcWorld and an MVC4 project named HelloMvcWorld.
You can have multiple tokens for lad, so I might look at allowing the solution name to be different from the project name, but I don’t think that’s really a big deal for now.
To get it all fired up, switch to the new solution, run xbuild, switch to the MVC project folder, and run xsp4.
1 2 3 4
Browse to localhost:8080 and you’ll see your brand new MVC4 app! Flip yeah! It’s pretty bare bones at the moment, but it’s a handy starting point for mucking about. I’m thinking of making one that’s a bit more fancy, for example pulling in the nuget packages for twitter bootstrap etc. But this does the job for now.