add-migration fails due to incompatability of packages - c#

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

Related

Stuck in asp.net core tutorial. Trying to use package manager console to add EF Core SQL Server provider does not work

I am following this beginners tutorial on Microsoft's site.
At this step...
In the PMC, run the following command:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
When I enter that command I get these messages and errors..
PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
Restoring packages for C:\projects\LazerbaseASPNET\LazerbaseASPNET\LazerbaseASPNET.csproj...
GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/index.json
OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/index.json 208ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/6.0.7/microsoft.entityframeworkcore.sqlserver.6.0.7.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/6.0.7/microsoft.entityframeworkcore.sqlserver.6.0.7.nupkg 71ms
Installed Microsoft.EntityFrameworkCore.SqlServer 6.0.7 from https://api.nuget.org/v3/index.json with content hash D9YV3hc3VSN1qrfdrZcKtMcRLT6bUqj8KtaUdkmO1CH/+meL+8z3Rge5iPhwQ4ol2AwPQlQYVPTTajf9ulSFGg==.
Install-Package : NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 6.0.7 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore.SqlServer 6.0.7 supports: net6.0 (.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package restore failed. Rolling back package changes for 'LazerbaseASPNET'.
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:03.2286177
Seems the important one is this...
Package Microsoft.EntityFrameworkCore.SqlServer 6.0.7 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore.SqlServer 6.0.7 supports: net6.0
This tutorial is for asp.net core 3.1.. It seems to be the one they recommend for beginners also. I am at a impass and have no idea how to proceed.
EDIT:
I think this is cus I used Visual Studio 2019 which I already had installed for Unity.. asp.net core 3.1 was the only option available for a new project... I think I need to wipe the existing server from azure, download Visual Studio 2022 and start again with a asp.net core 6 app ?
You can try to install entity framework core through the nuget package manager.
Rightclick on your project -> Manage Nuget packages. Before installing select the correct version from the dropdown for the netcore app version you are running.
I think this is cus I used Visual Studio 2019 which I already had installed for Unity.. asp.net core 3.1 was the only option available for a new project.
The solution is wipe the existing server from azure, download Visual Studio 2022 and start again with a asp.net core 6 app.
FML.
I also want to point out that this tutorial is wrong. Earlier in it it says requirement is Visual Studio 2019 16.4 or later.
I did read this and checked the version of Visual studio I had installed, I met the requirements so I kept going.

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:

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.

Downgrading Entity Framework for visual studio 2010

I accidentally upgraded my entity framework to EF 6.x but I am working in Visual Studio 2010 which does not have Dbcontext generator template support for ef 6.x, I was wondering if and how I could downgrade it to ef 4.x
I have tried searching in Nugget,
as well as typing Install-Package EntityFramework -Version 4.1.10331 Into the package console but I ended up with errors.
error :
Install-Package : Updating 'EntityFramework 6.1.1' to 'EntityFramework 4.1.10331.0' failed. Unable to find a version of 'EntityFramework.Extended' that is compatible with 'EntityFramework 4.1.10331.0'.
At line:1 char:16
+ Install-Package <<<< EntityFramework -Version 4.1.10331
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
If you are using Nugget I advise you to do this:
Uninstall-Package EntityFramework -Version 6.1.1
then install the older
Install-Package EntityFramework -Version 4.1.10331
"Updating" to an older version will create problems.
My issue ended up being that I also had a package called
EntityFramework.Extended 6.1.1, This package depended on EF6 and prevented it from being uninstalled, in turn preventing EF4 from being re-installed. Also This Package had no compatible version with EF4.
Upon removing EntityFramework.Extended I was able to fix my error.

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