Recently, I finished upgrading my ASP.NET MVC 4 application(in Visual Studio 2012) from .NET 4.0 to .NET 4.5 framework. Not-so-easy job though. A lot of pain and anxiety is involved when you migrate to a different target framework version and when you know that you have a lot of Nuget package references and use a couple of third-party components that interface with a specific version of .NET framework. So, i thought of sharing my experiences and challenges during this process.
The easiest way to target all projects to .NET 4.5 framework is by doing a search for all *.csproj files and replace <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> with <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> (or client profile, etc). You would also need to replace the <compilation> element's targetFramework=”4.0″ with 4.5 in the application's web.config file.
Issues after migrating ASP.NET MVC solution from .NET 4.0 to .NET 4.5:
<Reference Include="EntityFramework, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath> </Reference>
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.
Open Visual Studio 2012,
Go to “Tools” > “Library Package Manager” > “Package Manager Console”. This will open a powershell command prompt,
then type: uninstall-package EntityFramework for each of the listed projects for the default project dropdown.
After uninstalling EntityFramework from each of the projects, install EntityFramework by typing “install-package EntityFramework” in the powershell command-prompt.
NuGet 2.0 doesn't handle re-targeting your applications very well. In order to change your packages' target frameworks, you must uninstall and reinstall the packages.
The reasons why packages must be uninstalled and re-installed are:
2. ELMAH and Ninject work like a charm without any changes. That's a good news.
3. Make sure you take a look into 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 .
4. Lastly, 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.