在 .NET 7.0 项目中创建 Razor 页面时出现错误“无法加载文件或程序集 'Microsoft.EntityFrameworkCore,Version=7.0.12.0'”

问题描述 投票:0回答:1

我在尝试使用 EF Core 在 .NET 7.0 项目中创建 Razor 页面时遇到错误。错误消息指出:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" />
  </ItemGroup>

</Project>

我正在使用 .NET 7.0 和 Visual Studio 2022 版本 17.6.4

asp.net-core razor-pages code-generation .net-7.0 ef-core-7.0
1个回答
0
投票

尝试以下代码:

<ItemGroup>
      <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" />
    </ItemGroup>
© www.soinside.com 2019 - 2024. All rights reserved.