0

I first had this issue after new version of EntityFramework came out. It says I could not Add-Migration because The EntityFramework package is not installed on project . Now before links This Answer. It's not that - see below:

enter image description here

And it is absolutely installed:

  <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="6.0.3" />
    <PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Discounted.Models\Discounted.Models.csproj" />
  </ItemGroup>

</Project>

I originally fixed this issue by updating the packages.

I have tried:

  • Rebuilding/Cleaning as well as
  • Deleting the the obj & bin folders
  • Restoring the the Project & Solution
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
  • @Michael I don't run my migrations assembly from that project - no need to have it installed in the project, only in the same project as your entry point. – CorrieJanse Mar 19 '22 at 04:34
  • 1
    The error is strange and seems to come from "classic" Entity Framework (EF6) rather than EF Core 6.0. Try `Get-Help Add-Migration` and see what it outputs. – Ivan Stoev Mar 19 '22 at 10:24
  • 1
    @IvanStoev as it turns out I had both Core and normal EF installed at some point. After uninstalling it the error still persisted until I restarted the program. – CorrieJanse Mar 20 '22 at 11:26

2 Answers2

2

There was two versions of Entity Framework Installed. After uninstalling the regular EF I had to restart visual studio to get it working.

CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
0

Oh my God I Solved It....In Visual Studio 2022 , you must Install NGet Packages are important .

NUGET Packages

  1. EntityFramework - Version 6.4.4 .
  2. Microsoft.EntityFrameworkCore - Version 6.0.11.
  3. Microsoft.EntityFrameworkCore.Relational - Version 6.0.11
  4. Microsoft.EntityFrameworkCore.SqlServer - Version 6.0.11
  5. Microsoft.EntityFrameworkCore.Design - Version 6.0.11
  6. Microsoft.EntityFrameworkCore.Tools - Version 6.0.11

I used code first approach ... My Error

enter image description here

Follow ME:

PM> EntityFrameworkCore\Add-Migration
cmdlet Add-Migration at command pipeline position 1
Supply values for the following parameters:
Name: "Initial-Migraion"

enter image description here

PM> EntityFrameworkCore\Update-Database
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Update-Database' for Entity Framework 6.
Build started...
Build succeeded

enter image description here

.

Ragab Mohamad
  • 371
  • 2
  • 4