0

I have web-form project (project A) which has reference to another class library project (Project B) which I use for Data Access Layer, and I made another class library (Helper project-Project C) I make this Helper project as startup project when I want to run commands such Add-Migration on the DAL project, because it gives error if I make Project A or B as startup projects when I run EFCore commands.

It was working fine and I was able to add migrations & update database, but suddenly I got an error when I wanted to add Add-Migration, the error says:

Your startup project 'XXX.Helper' 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

Project B & C is using .NETFramework 4.7.2, and Project A was .NETFramework 4.5 & later I changed it to .NETFramework 4.7.2. I am using EntityFramework v3.1.15

How can I resolve this?

user1947393
  • 153
  • 4
  • 18

3 Answers3

0

Shouldn't your entity framework version be EF6 instead of EntityFramework Core if you are using NET Framework 4.7.2, because the current version of EF that is V 3.1 is EF Core which was designed for EF Core.

While it's not impossible to use certain NET core libraries in a NET Framework, there can be various problems with compatibility.

Regardless your project is most likely missing this reference to the design library of EF Core: https://learn.microsoft.com/pt-br/ef/core/cli/services

You can access your project csproj file and add the following to the rest of your PackageReferences:

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.11">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
  • Thank you. I have selected EfCore 3.x.x because I see in this link that NetFramework 4.7.2 supports EFCore 3.1 https://learn.microsoft.com/en-us/ef/core/miscellaneous/platforms. And I already installed Microsoft.EntityFrameworkCore.Design in all my projects but error available – user1947393 Jul 12 '21 at 19:48
  • It does, I edited my answer to be more clear on the missing reference – Rafael Bronzatti Jul 12 '21 at 19:49
  • I am using packages.config , where I can added all? – user1947393 Jul 12 '21 at 19:52
0

Work for me, Include on your csproj:

<PropertyGroup>
  <TargetFramework>net5.0</TargetFramework>
  <GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

Rebuild.

Suggested by: https://stackoverflow.com/a/58185466/5790169

Diego Lobo
  • 156
  • 7
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 20 '21 at 15:00
0

It looks like you also have EFCore installed, perhaps in another project in your solution.

If this is the case then you should explicitly specify that you want to use the EFFramework migration commands, rather than the EFCore versions of those commands

EntityFramework6\Update-Database

or

EntityFramework6\Add-Migration
Chris H
  • 501
  • 1
  • 4
  • 11