'Adding ADO.Net Entity Framework gives "The project's target framework does not contain Entity Framework runtime assemblies"

I've added a new .Net 6.0 project to my solution in VS2022. Installed the EntityFramework 6.4.4. with install-package entityframework and now try to add a ADO.Net Entity Framework Model to the project. I get an error:

The project's target framework does not contain Entity Framework runtime assemblies. Please review the target framework information on the project's property page.

I've tried adding several other EF packages (which should not be necessary according to the documentation here: https://docs.microsoft.com/en-us/ef/ef6/fundamentals/install). I thought the problem was with my installation but I created a .Net 6.0 console application containing the problem and sent it to a colleague and he got the same message.

Also found this topic here: Adding Entity Framework Model on Visual Studio 2022 but there's no answer there.

Steps to reproduce:

  1. Create a .Net 6.0 Console application.
  2. Install the EF6 package using install-package entityframework from the package manager console window.
  3. Right-click solution and choose 'Add' => 'Add item'.
  4. In the left pane click 'Data'.
  5. Choose 'ADO.Net Entity Framework Model.
  6. Click 'Add'.

enter image description here

The error appears:

enter image description here



Solution 1:[1]

The problem is that EF for .Net 6.0 only works with commands. A colleague sent me this link:

https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx

There the Scaffold-DbContext command is explained and that works just fine.

Solution 2:[2]

I know that almost all the other answers recommends to change the target framework, but some users (including me) needs to use .NET 6.0 instead of .NET Framework, so that solution its not valid for us.

I was able to create the models by using Paul Sinnema's link and using SQL authentication instead of Windows Auth (in my case):

You will need to install the following packages from NuGet:

Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools 

Afted that run the following command in the Package Manager Console: (Tools>Nuget Package Manager>Package Manager Console)

PM> Scaffold-DbContext "Server=.\LOCAL_SERVER;User ID=YOUR_DB_USER;Password=YOUR_DB_PASSWORD;Database=YOUR_DATABASE;Trusted_Connection=False;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

Solution 3:[3]

Firstly, you need to choose the correct Type of your project (i.e., when creating the project, choose "Console App (.NET Framework)", not the "Console App". This will solve the above error. I had the same error with Visual Studio 2022 using .NET 6, which got resolved after doing this correction

Screenshot

Solution 4:[4]

The EF 6 tooling onl works on a .NET Framework project, you must add one to your slution and then copy or link to the generated code. In addition, EDMX files in .NET Core projects are not supported, but there are workarounds

Solution 5:[5]

.Net Core 5 and .Net Core 6 both do not support use of the Entity Data Model Wizard that is launched when using the 'Add New Item' -> 'ADO.NET Entity data Model' window in Visual Studio.

As other have mentioned you may change the target version to .Net Framework 4.8 or similar to enable the use of this wizard.

However I like a different approach. Instead I add a class library to my solution that targets .Net Framework 4.8. Then in that class library I use the 'Add New Item' -> 'ADO.NET Entity data Model' which launches that handy wizard that creates the data models for my tables.

You can then build out this class library to handle all of your EntityFramework actions for that particular database. Or you can install the EntityFramework package and reference the classes from within the original project. Just make sure you remember to add the class library as a reference and dependency to your original project in the solution.

You can really do whatever you want with the classes after you have the wizard generate them for you.

Solution 6:[6]

Try to install Dot Net Framework lower versions manually or use a visual studio installer to modify the versions. After creating a project right click and go to properties, where you can change the target version. I changed it to 4.8 and the ADO Entity Model is working fine for me

Screenshot

Solution 7:[7]

u must at first select Console App(.Net Framework) not console application

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul Sinnema
Solution 2
Solution 3 Jeremy Caney
Solution 4 ErikEJ
Solution 5
Solution 6 Ramil Aliyev
Solution 7 mehran babayi