Nuget: Failed to add reference to 'EntityFramework' - c#

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:

Related

The package requires NuGet client version '3.6.0' or above

I want to install Microsoft.EntityFrameworkCore and its component. I am using Visual Studio 2015 with NuGet Client version previously 3.5.0 and now I have 3.6.0-rtm-2511 (which is the latest) downloaded from https://www.nuget.org/downloads as instructed by error report. I don't know why issue still persist that I need to have 3.6.0 or higher.
How to update my NuGet Package Manager in other way?
I can't find my Nuget Package Manager for Visual Studio in Update from Tools > Extension and Updates > Updates > Visual Studio Gallery.
I can only see it in Tools > Extension and Updates > Installed but there is no update for it but I noticed that 'Automatically update this extension' is checked.
Result from PM Console
PM> install-package microsoft.entityframeworkcore.sqlserver
GET https://api.nuget.org/v3/registration3-gz-semver2/microsoft.entityframeworkcore.sqlserver/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/microsoft.entityframeworkcore.sqlserver/index.json 329ms
Retrieving package 'Microsoft.EntityFrameworkCore.SqlServer 2.1.1' from 'nuget.org'.
Install failed. Rolling back...
Uninstalling NuGet package Microsoft.EntityFrameworkCore.SqlServer.2.1.1.
Executing nuget actions took 162.34 ms
install-package : The 'Microsoft.EntityFrameworkCore.SqlServer 2.1.1' package requires NuGet client version '3.6.0' or above, but the current NuGet
version is '3.6.0-rtm-2511'. To upgrade NuGet, please go to http://docs.nuget.org/consume/installing-nuget
At line:1 char:1
+ install-package microsoft.entityframeworkcore.sqlserver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Time Elapsed: 00:00:33.0573364
The package requires NuGet client version '3.6.0' or above
This is a known issue about nuget. NuGet team fixed it for Nuget 4 which comes with VS2017, but 2015 users are left behind.
Ticket: https://github.com/NuGet/Home/issues/6403
Besides, NuGet team will consider a fix. At this time there are no plans to release a new version of NuGet for VS 2015.
So if you want to use the package Microsoft.EntityFrameworkCore.SqlServer 2.1.1, you have to update your Visual Studio 2015 to Visual Studio 2017. Or if the lower version of this package is acceptable to you, you can use the version Microsoft.EntityFrameworkCore.SqlServer 2.0.3
Hope this helps.
Edit the files:
%userprofile%\.nuget\packages\microsoft.entityframeworkcore\3.1.8\microsoft.entityframeworkcore.nuspec
%userprofile%\.nuget\packages\microsoft.entityframeworkcore.abstractions\3.1.8\microsoft.entityframeworkcore.abstractions.nuspec
%userprofile%\.nuget\packages\microsoft.entityframeworkcore.analyzers\3.1.8\microsoft.entityframeworkcore.analyzers.nuspec
%userprofile%\.nuget\packages\microsoft.entityframeworkcore.relational\3.1.8\microsoft.entityframeworkcore.relational.nuspec
%userprofile%\.nuget\packages\microsoft.entityframeworkcore.tools\3.1.8\microsoft.entityframeworkcore.tools.nuspec
Change line 3 from:
<metadata minClientVersion="3.6">
to:
<metadata minClientVersion="3.6.0-rtm-2511">
Now go back to the Package Manager Console and try the install again:
Worked for me.
Try installing the package from Nuget Package Manager (Manage NuGet Packages)and not from console. The package manager will provide you option to update your NUGET application. Look in the 'Visual Studio Gallery' section of the 'Extension and Updates' window that pops up.

Nuget misbehaving with newtonsoft.json package

Why Nuget producing an error when I install a package after Newtonsoft.Json v11.0.2 is installed. Whenever I try to install another package I get the following error
Install-Package : An error occurred while retrieving package metadata for 'Newtonsoft.Json.11.0.2'
from source 'C:\Users\yusuf\Documents\Visual Studio 2015\Projects\Eman\packages'.
At line:1 char:1
+ Install-Package MaterialDesignThemes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.
InstallPackageCommand
Whenever i remove the line with the Newtonsoft.json package defined in packages.config the package installs successfully. Is it something wrong with json package itself or is it my package manager that's messed up, anyway can someone show me how i can fix this.
P.S. This happens with whichever package i try to install while json package is already installed.
EDIT I tried deleting the package line in packages.config and also deleting the downloaded package files and reinstalled the package several times, i keep getting the same problem
First, downgrade Newtonsoft.Json v11.0.2 to Newtonsoft.Json v6.0.4. Second, install another nuget package.
If the package successfully installs, upgrade Newtonsoft.Json v6.0.4 back to Newtonsoft.Json v11.0.2.

'System.Net.Http' already has a dependency defined for 'System.Runtime'

I'm trying to install the MaxMind MinFraud package via NuGet. Whenever I try, I get the following back -
PM> install-package MaxMind.MinFraud
Attempting to resolve dependency 'System.Net.Http (≥ 4.0.0)'.
install-package : 'System.Net.Http' already has a dependency defined for 'System.Runtime'.
At line:1 char:1
+ install-package MaxMind.MinFraud
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
A few other similar questions here suggested restarting VS, manually adding a reference to System.Net.Http and clearing NuGet Package Cache, and changing the target framework to 4.6.2 (originally 4.5), all of which did not work for me.
Any ideas on what I can try next?
I installed this package successful in my Visual Studio 2015 Update 3 project with NuGet Package Manager 3.4.4.
So please make sure your are using the latest version of Visual Studio 2015 and NuGet Package Manager.

Installing Entity Framework fails in Visual Studio 2015

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.

The source at nuget.org is unreachable?

I'm trying to install SignalR in my C# project, but all I get when running install-package Microsoft.AspNet.SignalR is:
The source at nuget.org [https://www.nuget.org/api/v2/] is unreachable. Falling back to NuGet Local Cache(...)
At line:1 char:1
+ install-package Microsoft.AspNet.SignalR
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
This error was posted to Stack Overflow a few times, but no solution has worked for me. I've tried:
Starting a new project
Removing and adding all of my nuget sources
Trying nuget with projects where it worked
Reinstalling nuget
Reinstalling Visual Studio
Nothing worked. I can reach nuget.org just fine from my browser.
I would appreciate some help.
Try using the UI. For me the UI works fine but the Package Manager needs to be told explicitly where the source is. Try the command:
install-package Microsoft.AspNet.SignalR -Source nuget.org
To work around this, you can run nuget install Microsoft.AspNet from the command line in your solution root. Then when you try again in the Package Manager it will find the cached copy and succeed:
.nuget\NuGet.exe install Microsoft.AspNet.SignalR.Client -OutputDirectory packages

Categories