Instead, maybe you should try Visual Studio for Mac.
This is an update to the earlier post Setup ASP.NET MVC 4 on MonoDevelop 4.1.
I don’t particularly like programming on Windows because of my hands’ muscle memories use the Command, Option, and Control keys, not the CTRL and ALT keys. To continue Web programming, I try to do as much ASP.NET MVC programming on Mac OS X rather than Windows. I use Xamarin Studio neé MonoDevelop to do that. It can hurt to get it all set up, so I present the instructions here.
This post assumes you do not have any mono or mono-related components on your system. If you do, fire up a VM. If you don’t, fire up a VM. Do all of this in a VM. It keeps your real development environment pristine.
Note: In this post, when I mention MonoDevelop 4.2.2, that also means Xamarin Studio 4.2. You won’t see MonoDevelop 4.2 in your Applications folder, so just accept the fact that I use the terms interchangeably.
You can get them from the MonoDevelop Web site. Make sure that you get MonoDevelop 4.2.2 and Mono 3.2.6 Mono MDK installer.
Install them as you do programs on your system. On Mac OS X, run the MDK PKG to install Mono. Then, mount the Xamarin Studio DMG and drag the app into the Applications directory.
Under the “Xamarin Studio” application menu, click the “Add-in Manager…” menu item.
On the ensuing dialog, click the “Gallery” tab. Choose the “Manage Repositories…” item in the “Repository” selector.
In the ensuing dialog, click the “Add” button.
In the ensuing dialog, paste the following URL into the “Url:” text field.
Click the “OK” button. Click “Close” button.
Expand the “IDE extensions” disclosure triangle and select the “NuGet Package Management” tree item.
Click the “Install…” button that appears in the detail box to the right of the tree view.
In the ensuing dialog, click the “Install” button. Wait for that operation to complete and the dialog to dismiss itself.
Click the “Close” button.
Click the “New…” button in the “Solutions”.
In the tree view, expand “C#” if you have to and select the ASP.NET item in the tree.
Choose whatever ASP.NET MVC 3 kind of project that you want to use. I will choose the “ASP.NET MVC 3 (Razor) with Unit Test Project” because it requires the most changes to get it to work correctly. Subsets of the changes in the following sections will work for the other types of MVC 3 projects available to you.
Enter the name of the Project and/or Solution and click the OK button.
Yeah, out of the box: broken. Let’s fix that and make it MVC 5 at the same time.
Right- or Control-click the MVC project and choose Options from the context menu. Choose the “General” node under the “Build” node in the tree view on the left of the “Project Options” dialog. Change the “target framework” value from “Mono / .NET 4.0” to “Mono / .NET 4.5”. Click the “OK” button.
Right- or Control-click the “References” tree item under your MVC project. Click the “Manage NuGet Packages…” context menu item.
In the ensuing dialog, ensure that the “Available” tab is active. Type “ASP.NET MVC” into the search field. Click the search button to the right of the input field. Scroll down until you see the package named “Microsoft ASP.NET MVC”. Select it by clicking on it. Then, click the “Add” button below the details pane to the right of the packages list.
In the ensuing dialog, read all of the licenses (yeah, right!) and click the “OK” button.
Click the “Close” button.
Right- or Control-click the “References” tree item under your test project. Click the “Manage NuGet Packages…” context menu item.
Activate the “Recent” tab. Select the “Microsoft ASP.NET MVC” package. Click the “Add” button. Click the “Close” button.
Now, you can build and run the default unit test to make sure everything things seem ok.
Try running it from the “Run” menu and clicking the “Start Debugging” menu item (or by the Command + Enter key combination). If you’re on Mac OS X, you may see an exception like this:
System.UnauthorizedAccessException Access to the path “/Library/Frameworks/Mono.framework/Versions/3.2.6/etc/mono/registry” is denied.
It seems that the ASP.NET debugger requires access to the registry that mono installs because the CLR expects a registry. This is easy to fix. Open Terminal and type (or paste) the following commands:
sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.6/etc/mono/registry
Now it can access the registry and everything is ok.
If you try running it, now, you will see an exception similar to the following:
System.InvalidOperationException Conflicting versions of ASP.NET Web Pages detected: specified version is “18.104.22.168”, but the version in bin is “22.214.171.124”. To continue, remove files from the application’s bin directory or remove the version specification in web.config.
Part of our upgrade process added new assemblies but did not change the .config files. Open the Web.config file in the root of the MVC project and change the line that reads
<add key=”webpages:Version” value=”126.96.36.199” />
<add key=”webpages:Version” value=”188.8.131.52” />
That fixes that! Give it a run.
Now we get an exception about not finding a view. It’s there! I promise! We have yet to update the MVC Web.config and that causes problems. Open the Web.config under the Views folder in your MVC project. Do the following find and replace steps:
- Find and replace the value “System.Web.WebPages.Razor, Version=184.108.40.206” with the value “System.Web.WebPages.Razor, Version=220.127.116.11”
- Find and replace the value “System.Web.Mvc, Version=18.104.22.168” with the value “System.Web.Mvc, Version=22.214.171.124”