I was listening to a recent .NET Rocks with Julie Lerman on Entity Framework 5, and she was asked if EF5 worked with both .NET 4.5 and .NET 4.0.
Around minute 26, she briefly mentioned it’s tricky because the dll that gets installed via NuGet is determined by the Target Framework the project is set to at the time you install EF via NuGet.
I ran across an easy way to tell today & wanted to share, while elaborating on what she said with pretty pictures =D.
NuGet writes a packages.config file in the root directory of every project a NuGet package has been installed in. Open it and you can quickly tell which version was targeted.
For example, my current .NET Framework 4.5 project, shows this:
When I create a .NET Framework 4.0 project & install EF5, I get this:
Here’s the Gotcha:
When I changed the Target Framework of my 4.0 project to 4.5, THIS DID NOT CHANGE.
Another important part that DID NOT CHANGE when I changed the target Framework was the section config:
The top one shows the App.config for the project I installed EF into that was set to target 4.5 when I installed the NuGet package.
The bottom one shows the App.config for the project I installed EF into that was set to target 4.0 when I installed the NuGet package AFTER I changed the Target framework to 4.5.
If you look at the EntityFramework Reference properties, you’ll see it actually installs different versions:
…;and not to beat a dead horse, but if you then look at the downloaded NuGet package in your solution root\packages\EntityFramework.5.0.0\lib, you’ll see there are completely separate dlls that get installed, depending on your Target Framework at the time of installation,
My Recommendation
Sure, there is probably some “change this and this and this and copy this and change this” manual way of modifying the settings & EF dll if you upgrade your framework, but do yourself a favor:
- Check everything into your Git branch
- “Manage NuGet Packages..” –> Uninstall EntityFramework
(or Uninstall-Package EntityFramework in the Package Manager Console) & - Reinstall EntityFramework
(or Install-Package EntityFramework in the Package Manager Console)
You will thank yourself in the morning :-)

October 5, 2012 at 8:56 AM
OK, but how can I upgrade my EF4.0 to EF4.4 on my existing projects? I’m adding the EntityFramework reference to my project, will it then use the newer one instead my old System.Data.Entity?
November 13, 2012 at 12:04 AM
My advice is to create a branch & try uninstalling EF via NuGet & then reinstalling EF via NuGet. That way you can just trash the branch if it blows up :-)
October 8, 2012 at 7:53 PM
if I change project version to .net 4.5 (from .net 4.0) will my EF I am using in that project automatically upgraded to 5.0 or i still need download EntityFramework.dll ? The thing i’ve never used
DbContext, my project only uses ObjectContext
November 13, 2012 at 12:03 AM
You’ll need to re-download if you used NuGet to install it. NuGet detects the project framework target at installation time & installs the dlls for that framework.