【问题标题】:'Microsoft.NETCore.App 2.0.0 not found in Package Manager Console'在包管理器控制台中找不到 Microsoft.NETCore.App 2.0.0
【发布时间】:2021-12-01 18:50:43
【问题描述】:

我最近将我的 .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>

如您所见,还有其他库项目也在使用中。

【问题讨论】:

  • 在旧版本中它是一个单独的 Nuget 包。您可以更新项目 SDK 版本,但此包仍可能位于您的 .csproj 文件中。您应该删除它,因为较新的版本不需要它。
  • @Eldar:嗯,这当然是有用的信息。但正如问题中提到的,我没有看到对这个包的任何引用。
  • 你能分享你的csproj文件内容吗?
  • 现在不推荐使用 .NET 2.0 SDK,Visual Studio 会警告您在安装时将其删除。
  • 我的意思是,在包管理器控制台中,标题 Default Project: a dropdown here 中有一个部分显示了所选项目。

标签: c# .net visual-studio .net-6.0


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-07-10
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 2021-06-09
    • 2015-08-24
    • 1970-01-01
    相关资源
    最近更新 更多