Installing Entity Framework fails in Visual Studio 2015 - c#

I'm reading/coding along with the Apress book Pro ASP.NET MVC 5 by Adam Freeman. In chapter 7 (p. 174), we're supposed to install Entity Framework using the following commands:
Install-Package EntityFramework -projectname SportsStore.Domain
Install-Package EntityFramework -projectname SportsStore.WebUI
But this fails. Here is the output:
Attempting to gather dependencies information for package 'EntityFramework.6.1.3' with respect to project 'SportsStore.Domain', targeting '.NETFramework,Version=v4.5.1'
Attempting to resolve dependencies for package 'EntityFramework.6.1.3' with DependencyBehavior 'Lowest'
Resolving actions to install package 'EntityFramework.6.1.3'
Resolved actions to install package 'EntityFramework.6.1.3'
Adding package 'EntityFramework.6.1.3' to folder 'C:\git\SportsStore\packages'
Added package 'EntityFramework.6.1.3' to folder 'C:\git\SportsStore\packages'
Added package 'EntityFramework.6.1.3' to 'packages.config'
Executing script file 'C:\git\SportsStore\packages\EntityFramework.6.1.3\tools\init.ps1'
Executing script file 'C:\git\SportsStore\packages\EntityFramework.6.1.3\tools\install.ps1'
Type 'get-help EntityFramework' to see all available Entity Framework commands.
Successfully installed 'EntityFramework 6.1.3' to SportsStore.Domain
Install failed. Rolling back...
Removed package 'EntityFramework 6.1.3' from 'packages.config'
Removing package 'EntityFramework 6.1.3' from folder 'C:\git\SportsStore\packages'
Access to the path 'C:\git\SportsStore\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' is denied.
Access to the path 'EntityFramework.PowerShell.Utility.dll' is denied.
Removed package 'EntityFramework 6.1.3' from folder 'C:\git\SportsStore\packages'
Install-Package : An item with the same key has already been added.
At line:1 char:1
+ Install-Package EntityFramework -projectname SportsStore.Domain
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
One or more packages could not be completely uninstalled: 'C:\git\SportsStore\packages\EntityFramework.6.1.3'. Restart Visual Studio to finish uninstall.
The book is instructing us to install specific versions of all other libraries (e.g. Microsoft.Aspnet.Mvc 5.0.0), but does not mention which version of EF to install, so I've tried installing different versions of EF, but keep getting the same error. (Install failed. Rolling back...)
I'm running VS2015 as administrator.

Seems NuGet itself was causing these issues (probably related to https://github.com/NuGet/Home/issues/1239, as I was seeing the same 'always rolling back' issue as discussed in that thread)
Updating NuGet solved it for me. (Updated from version 3.0.60624.657 to 3.1.60724.766)

These references were set up earlier in the project:
SportsStore.WebUI -> SportsStore.Domain
SportsStore.UnitTests -> SportsStore.Domain and SportsStore.WebUI
I removed the references for each project and then ran the install-package command for the Entity Framework as directed. That worked fine.
I then re-added the references.

Try to remove all the EF nuget packages installed on your solution and then reinstall the only one that you need.

Try to disconnect references between projects and than try to install EF. Hope it'll help

Relaunching Visual Studio as Admin and retry to install the package did the trick for me.

Related

Unable to install a Nuget Package in a .NET Framework 4.7.2 project

In my WPF project using .NET Framework 4.7.2 in VS2017, I'm trying to install Interop.MSUtil.dll NuGet package as suggested here. I do need this package installed, so could someone please help me installing it or providing a workaround.
Error:
Install-Package : Could not install package 'Interop.MSUtil.dll 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2',
but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package Interop.MSUtil.dll -Version 1.0.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
It appears that the NuGet package for Interop.MSUtil.dll is not compatible with the .NET 4.7.2 Framework.
However, if you have LogParser installed on your machine and you have administrator access, you can recreate it locally.
Locate your copy of LogParser. The most likely place is in C:\Program Files (x86)\Log Parser 2.2.
Locate your Developer Command Prompt. In Windows 10, just type developer command prompt into the Windows search bar.
Run it as Administrator. Generally this can be done by right-clicking on the Developer Command Prompt item for the context menu.
cd to the location where LogParser is installed.
Run the following command:
tlbimp LogParser.dll /out:Interop.MSUtil.dll
This should build a new version of Interop.MSUtil.dll which will be friendly to your version of the Framework.
Now you can add it as a reference manually by browsing to the LogParser directory and selecting the new DLL.
Don't forget you may need to set Embed Interop Types to False.
Note that this draws heavily from this previous answer.
If Nuget package is not declared to be installed it can't be installed through the package manager.
However you can install a .dll file. First install it on the some project where it can be installed. Then in packages folder of the project find some .dll file that you find appropriate. Finally add it as the reference to the project. It may or may not work depending on the package itself but that is the only way if it has any chance to work.

'System.Xaml' which was not found in the GAC

Trying to update Microsoft.Build.Framework using Nuget in my SLN and getting the below error. This is VS 2017 Enterprise Version 15.9.1
Projects all target NET461 in this sln.
I duplicated this problem on 2 different windows 10 machines with the same project.
What can I do to get these packages updated?
Output
Attempting to gather dependency information for package 'Microsoft.Build.Framework.15.8.166' with respect to project 'Synovia.Service', targeting '.NETFramework,Version=v4.7.2'
Gathering dependency information took 3.08 sec
Attempting to resolve dependencies for package 'Microsoft.Build.Framework.15.8.166' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.Build.Framework.15.8.166'
Resolved actions to install package 'Microsoft.Build.Framework.15.8.166'
Found package 'Microsoft.Build.Framework 15.8.166' in 'D:\git\sbss\Source\packages'.
GET https://api.nuget.org/v3-flatcontainer/microsoft.build.tasks.core/15.7.179/microsoft.build.tasks.core.15.7.179.nupkg
GET https://api.nuget.org/v3-flatcontainer/microsoft.build.utilities.core/15.7.179/microsoft.build.utilities.core.15.7.179.nupkg
Retrieving package 'Microsoft.Build.Tasks.Core 15.7.179' from 'nuget.org'.
Retrieving package 'Microsoft.Build.Utilities.Core 15.7.179' from 'nuget.org'.
Found package 'Microsoft.VisualStudio.Setup.Configuration.Interop 1.16.30' in 'D:\git\sbss\Source\packages'.
Removed package 'Microsoft.Build.Framework.15.6.82' from 'packages.config'
OK https://api.nuget.org/v3-flatcontainer/microsoft.build.utilities.core/15.7.179/microsoft.build.utilities.core.15.7.179.nupkg 53ms
Installing Microsoft.Build.Utilities.Core 15.7.179.
OK https://api.nuget.org/v3-flatcontainer/microsoft.build.tasks.core/15.7.179/microsoft.build.tasks.core.15.7.179.nupkg 78ms
Successfully uninstalled 'Microsoft.Build.Framework.15.6.82' from Synovia.Service
Installing Microsoft.Build.Tasks.Core 15.7.179.
Removed package 'Microsoft.Build.Tasks.Core.15.6.82' from 'packages.config'
Successfully uninstalled 'Microsoft.Build.Tasks.Core.15.6.82' from Synovia.Service
Removed package 'Microsoft.Build.Utilities.Core.15.6.82' from 'packages.config'
Successfully uninstalled 'Microsoft.Build.Utilities.Core.15.6.82' from Synovia.Service
Package 'Microsoft.Build.Framework.15.8.166' already exists in folder 'D:\git\sbss\Source\packages'
Install failed. Rolling back...
Package 'Microsoft.Build.Framework.15.8.166' does not exist in project 'Synovia.Service'
Package 'Microsoft.Build.Utilities.Core.15.6.82' already exists in folder 'D:\git\sbss\Source\packages'
Added package 'Microsoft.Build.Utilities.Core.15.6.82' to 'packages.config'
Package 'Microsoft.Build.Tasks.Core.15.6.82' already exists in folder 'D:\git\sbss\Source\packages'
Added package 'Microsoft.Build.Tasks.Core.15.6.82' to 'packages.config'
Package 'Microsoft.Build.Framework.15.6.82' already exists in folder 'D:\git\sbss\Source\packages'
Added package 'Microsoft.Build.Framework.15.6.82' to 'packages.config'
Executing nuget actions took 6.84 sec
Failed to add reference. The package 'Microsoft.Build.Framework' tried to add a framework reference to 'System.Xaml' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance.
Reference unavailable.
Time Elapsed: 00:00:10.1224742
========== Finished ==========
'System.Xaml' which was not found in the GAC
Your project is probably target .Net 3.5, which does not have this DLL. You can update the framework version in Project Properties.
If above not resolve your issue or you do not want to change your framework version, you can manually add the reference System.Xaml to your project:
Go to References -> Add Reference... and then click on Browse..
Add the file, which is located on (Windows 10): C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll
Then update your nuget package.
Hope this helps.

add-migration fails due to incompatability of packages

I have a connection to a SQL Server database I created in Micrososft SQL Server Management Studio. I am connected using my current ip.
The day I opened the connection and the database I also created a table using migrations and Entity Framework, and the table was created successfully.
Returning to work after turning off the computer at night and then back at the morning, I try to perform add-migration in PM Console I get the error:
Your startup project 'TowerOfPower' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
Weird, but then when I try installing the package
Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.1.0
I get the error:
Install-Package : Could not install package 'Microsoft.EntityFrameworkCore.Design 2.1.0'. You are trying to install this package into a project that targets
'.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.1.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
So I tried to fix this by installing other packages as suggested on the web, but still got the last error I mentioned for all of them.
I think there is a big contradiction about your framework types. Firstly, If you develope .NetCore project, you have to use EfCore for ORM progress. In .NetFramework project, you have to use Entity Framework.
If we look at the latest error message,
You are try to load incorrect nuget project. According to error message you are try to install EntityFrameworkCore packege to ".NETFramework,Version=v4.0'" For this framework you have to use Install-Package EntityFramework -Version 6.2.0
Lastly, If you use multiple project in single solution, you have to be sure about project frameworks types (exp: .Net or .NetCore)
When you use Package Manager Console, you have to chose correct project in Default Project ComboBox

Nuget: Failed to add reference to 'EntityFramework'

I tried to update a few packages using Package Manager Console, but I am getting this:
update-package : Failed to add reference to 'EntityFramework'.
At line:1 char:1
+ update-package EntityFramework -reinstall
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Update-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand
Here are a few commands that I tried:
Install-Package EntityFramework
Update-Package EntityFramework -Reinstall
Update-Package -Reinstall
I also tried to update packages using UI and ran VS in administrator mode. Important to mention, the project is under TFS source control (I did make it work when I removed TFS binding). There are a few other packages - same thing with them. I see yellow exclamation next to references and I can't re-install packages.
I've never seen this error before, similar question answers don't work for me.
In my case packages where checked in TFS source control (which is of course terrible). This answer explains how to setup ignore rules for TFS. After deleting packages everything was fixed.
I've tried your commands on one of my project that under VSTS source control, no issue occurred (VS 2015.3 + Package Manager Console Host Version 3.5.0.1484). You may try the items below:
Check Package Manager Console version to see whether it is the latest version.
Try to open the package from Manage Nuget Packages, uninstall the EntityFramework package and re-install it:
Enable Package restore in VS:

How to install EntityFramework 5.0 (and other older versions) from NuGet?

I installed EF 5.0 into the .DAL, now I want to install EF 5.0 into .BLL from Nuget
But the default online Nuget package always comes up with 6.0, which gives error when used together with the 5.0 EF I use in DAL.
Where can I install the 5.0 version of EntityFramework into my Nuget packages??
View -> Other windows -> Package Manager Console then run
install-package entityframework -version 5.0.0.0.
Add -project <project.name> if you want to install it in a specific project.
here is what I experienced: (before I begin... kudos to devnull for the answer).
I clicked on:
1) View -> Other windows -> Package Manager Console then ran
2) install-package entityframework -version 5.0.0.0.
The uninstall started, but then rolled back, as it detected I already had installed Entity Framework (EF) 6.0.2 ...
>PM> install-package entityframework -version 5.0.0.0
Installing 'EntityFramework 5.0.0'.
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 5.0.0'.
*****Install failed. Rolling back...*****
install-package : Already referencing a newer version of 'EntityFramework'.
At line:1 char:1
+ install-package entityframework -version 5.0.0.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
So then I uninstalled the Entity Framework 6.0.2 and found it had a dependency that also needed to be removed... then I was finally able to uninstall the Entity Framework 6.0.2 and then add the Entity Framework 5.0.0.0
PM> uninstall-package entityframework -version 6.0.2
uninstall-package : Unable to uninstall 'EntityFramework 6.0.2' because 'AnotherFakeDbSet 3.0.0.0' depends on it.
So then I uninstalled these two and installed Entity Framework 5.0.0.0
PM> uninstall-package AnotherFakeDbSet -version 3.0.0.0
PM> uninstall-package entityframework -version 6.0.2
PM> install-package entityframework -version 5.0.0.0
I like the console... quicker than searching for the packages if you know the version #. And if you haven't checked out "Powershell" (the basis for the console -- I find it's time well spent - it allows for virtually unlimited automation)
Older versions of Entity Framework or other similar packages can be installed using Package Manager Console only in earlier versions of Visual Studio (prior to 2015). In Visual Studio 2015 there is an option of manually selecting version before install but in Visual Studio 2010,2012 you need to use package manager console only.
Simple browse to the link Nuget Explorer and click on the specific entity version that you have to install.
You'll see that Studio automatically shows the Package Manager console code.
For example I was working on a project that required Entity Framework 4.1 So here was my code. Entity Framework Package Manager Console Command Snapshot

Categories