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 Views\web.config file, which caused some compatibility problems.

This is what I did:

1. Create a Web API One ASP.NET project

clip_image002

2. Manage NuGet packages, find HotTowel: ASP.NET MVC SPA Template package, click Install.

clip_image004

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 Views\web.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=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘Default’ at location ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll’. Type B originates from ‘System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘Default’ at location ‘C:\Users\xinqiu\AppData\Local\Temp\Temporary ASP.NET Files\root\3c4ae604\700fa44c\assembly\dl3\8be5ce88\7c28f49b_e28fce01\System.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.