Ivan's Space

Writing about leadership, management, emotional resiliency, software engineering, tech, gadgets.




read

You can find a very handy step by step guide for migrating to ASP.NET MVC 4 here . It might seem a bit long, but actually with a few multi-file search and replace and some regex you can do it pretty quickly.

I just wanted to add a few more tips:

Migrating to ASP.NET MVC 4

If you are still using bin deployables (“Add Deployable Assembly”) for your current ASP.NET MVC setup – you should remove it and replace it with the AspNetMvc nuget package.

If you are using MvcContrib or MvcFutures – it’s probably best to update to* MvcContrib.Mvc3-ci *and *Mvc3Futures . *Either case you will have to deal with the clash of extension methods (Html.IdFor, Html.NameFor, etc) which were previously in Mvc Futures (Microsoft.Web.Mvc.dll) but now are part of the core ASP.NET MVC assembly. Until updated versions of MvcContrib and MvcFutures come out I have resolved this by removing the  using statement from my View’s Web.config for the MvcFutures extensions methods namespace. This however means that you lose tiny things like Html.SubmitButton, which you can easily replace across the whole solution with html code using a Regex.

Be careful about underwater rocks like this one about the new Date and DateTime editor templates in MVC 4. Also there seem to be model binding changes to do with DateTime – so far that has been the major pain in the ass for me.

Re-targeting for .NET 4.5

The fastest way to convert all projects is by doing a search and replace across all .csproj files and replace v4.0  with v4.5 *(or client profile, etc)

also replace in your Web.config compilation element targetFramework=”4.0″ with 4.5

The real issue are the NuGet packages – some have a .NET 4.5 specific version – a good example is Entity Framework. When the project is targeting version 4.0 of the framework and you install/update EF to version 5 you actually end up with EF 4.4 (which doesn’t have support for enums and so on). The only way to solve this is to remove all packages and install them again, which is a massive pain to do manually and unfortunately the current version of NuGet is not of much help there either, but the daily build is. More details about retargeting the NuGet packages are available in this StackOverflow question.

A few other notes

Things that I have personally tested and work fine: MiniProfiler works fine with an runtime assembly binding redirect for Entity Framework, ELMAH and Ninject work without any changes. Noticed a small regression in unobtrusive validation and checkboxed when pulling a form with AJAX, but I that ended caused by a jQuery Validation problem.

Oh and by the way, don’t forget to update your test assemblies *App.config *with the correct assembly redirects if you are running tests against ASP.NET MVC controllers, which use MvcFutures or MvcContrib, because you will end up seeing weird “Type A doesn’t match type A” errors.

To be honest I haven’t seen noticeable performance improvements with the MVC 4 + .NET 4.5 + EF5 combo so far, but time will tell.

Blog Logo

Ivan Zlatev


Published

Image

Ivan's Space

Writing about leadership, management, emotional resiliency, software engineering, tech, gadgets.

Back to Overview