Install MVC4 HotTowel SPA NuGetNuGet package in One ASP.NET Web API Project in VS2013 Preview
I was trying to install MVC4 HotTowel SPA package (MVC4 and Razor v2) on a VS2013 Preview One ASP.NET Web API Project (MVC5 and Razor V3). I blindly let the NuGetNuGet package overwrite all my files including the Viewsweb.config file, which caused some compatibility problems.
This is what I did:
1. Create a Web API One ASP.NET project
2. Manage NuGet packages, find HotTowel: ASP.NET MVC SPA Template package, click Install.
3. I chose “Yes to All” when prompted for file overwriting. I should have chosen “Yes” and “No” buttons for each file overwriting warning dialog in order to prevent overwriting Viewsweb.config.
4. CTRL-F5 to run the application, I get the following error in IE:
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from ‘System.Web.WebPages.Razor, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘Default’ at location ‘C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.WebPages.Razorv4.0_126.96.36.199__31bf3856ad364e35System.Web.WebPages.Razor.dll’. Type B originates from ‘System.Web.WebPages.Razor, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘Default’ at location ‘C:UsersxinqiuAppDataLocalTempTemporary ASP.NET Filesroot3c4ae604700fa44cassemblydl38be5ce887c28f49b_e28fce01System.Web.WebPages.Razor.dll’.
5. It took me quite a while to figure out what was wrong since the ~/web.config is correct, until I realized there is also a Views/web.config file. After I manually corrected the Views/web.config file to match a normal Web API project Views/web.config file, the application works correctly with HotTowel features.
Later I found this experience matches the following StackOverflow question about migrating an MVC4 project to MVC5: http://stackoverflow.com/questions/17454852/upgrading-from-mvc4-to-mvc5-pre-release. So hopefully my simple mistake might have some value to be shared.