Error: 'Package restore failed rolling back package change for' while running Scaffold-Dbcontext in Entity Framework Core 7.0.14

120 views Asked by At

I'm encountering an issue while running Scaffold-DbContext using Entity Framework Core 7.0.14; I'm getting an error message

There was an error running the selected code generator package restore failed rolling back package change for

I'm curious about what steps I should take to resolve this issue.

Versions I'm using:

  • .NET Core 7
  • Entity Framework Core 7.0.14
  • Project GitHub link: GitHub Link
  • Visual Studio 2022

Does anyone have any help or suggestions regarding this issue? Thank you in advance.

I connect with dbcontext

but it doesn't work

public class ApplicationDbContext : IdentityDbContext
{
     public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
     {
     }

     public DbSet<Category> Categories { get; set; }
     public DbSet<Product> Products { get; set; }
     public DbSet<ProductPrice> ProductPrices { get; set; }
     public DbSet<OrderDetail> OrderDetails { get; set; }
     public DbSet<OrderHeader> OrderHeaders { get; set; }
}

I attempted to generate a DbContext using Scaffold-DbContext in Entity Framework Core 7.0.14 within my .NET Core 7 project. I expected the command to execute successfully and create the necessary DbContext based on my database schema. However, during the process, I encountered an error

There was an error running the selected code generator package restore failed rolling back package change for

Despite multiple attempts, I couldn't resolve this issue. Seeking advice on resolving this error in the context of .NET Core 7 and Entity Framework Core 7.0.14

1

There are 1 answers

0
Fengzhi Zhou On

Your "Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" is not compatible with your EF core version, you need to modify the EF core relating packages to 7.0.12

E_Commerce_Sercer

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

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

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.12" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.14" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.12" />  // This is auto-matically installed
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.12">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Syncfusion.Blazor.Grid" Version="19.4.0.56" />
    <PackageReference Include="Syncfusion.Blazor.RichTextEditor" Version="19.4.0.56" />
    <PackageReference Include="Syncfusion.Blazor.Themes" Version="19.4.0.56" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\E_Commerce_Business\E_Commerce_Business.csproj" />
    <ProjectReference Include="..\E_Commerce_DataAccess\E_Commerce_DataAccess.csproj" />
    <ProjectReference Include="..\E_Commerce_Models\E_Commerce_Models.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\images\product\" />
  </ItemGroup>

</Project>

E_Commerce-DataAccess

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.12">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>