'Microsoft.NETCore.App 在程序包管理器控制台中找不到 2.0.0

'Microsoft.NETCore.App 2.0.0 not found in Package Manager Console

我最近将我的 .NET 项目从 .NET 5.0 升级到了 .NET 6.0。

当我尝试在程序包管理器控制台中添加迁移时,出现以下错误。

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
  - The following frameworks were found:
      5.0.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      6.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64

我对此感到困惑。为什么它要寻找 Microsoft.NETCore.App 的 2.0.0 版本?那是旧版本吗?既然我已经将我的项目更新到 .NET 6.0,为什么它会丢失?

我查看了我的项目,但没有看到任何对此包的引用。任何人都可以帮助我了解哪里出了问题吗?

更新

这是我的主要应用程序的项目文件。

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\TTRailtraxBusinessLayer\TTRailtraxBusinessLayer.csproj" />
    <ProjectReference Include="..\TTRailtraxEntities\TTRailtraxEntities.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Attributes\" />
  </ItemGroup>

</Project>

这是包含我的实体的库项目的项目文件。

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\RailtraxCore\RailtraxCore.csproj" />
  </ItemGroup>

</Project>

如您所见,还使用了其他库项目。

好吧,Entity Framework 的 Powershell 工具具有将参数传递到 EF 工具的语义。它同时传递默认项目和启动项目,但对于多个启动项目,它使用默认项目作为回退项目。 EF 工具需要配置的 DbContext(与提供程序和连接字符串相关联),这是使用 DbContext 并对其进行配置的启动项目。以及定位迁移的迁移程序集,通常是包含 DbContext 的项目。所以通常当我使用 PMC 添加迁移时,我将启动项目设置为应用程序,并将 PMC 中的默认项目设置为 DbContext 项目。

Here 是 Powershell 模块,如果你想深入挖掘的话。

尝试将项目框架更改为找到的框架,即 3.1 或 5.0: 右键单击项目 -> 属性 -> 应用程序 -> 目标框架