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,
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 :-)