【问题标题】:Package Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 is not compatible with netcoreapp3.1 yet it's targeting net 5.0包 Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 与 netcoreapp3.1 不兼容,但它的目标是 net 5.0
【发布时间】:2021-03-13 19:00:10
【问题描述】:

我正在从 .Net Core 3.1 迁移到 .NET 5.0。

我不断收到此错误消息:

包 Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 与 netcoreapp3.1 (.NETCoreApp,Version=v3.1) / win-x86 不兼容。包 Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 支持:net5.0 (.NETCoreApp,Version=v5.0)

我明白它在说什么,但我不知道它为什么这么说。

我的项目面向 .NET 5.0。

我的 csproj 文件如下所示:

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <UserSecretsId>5e2f8086-7a94-402a-bd2a-4160e9236c8f</UserSecretsId>
  </PropertyGroup>


 <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
  </ItemGroup>

</Project>

我不确定它为什么告诉我 3.1。

我手动删除了 bin 和 obj 文件夹,尝试更新所有 nuget 包,并清理/重建项目,但每次都遇到相同的问题。v

我使用的是 Visual Studio 16.8.2。

编辑

我要指出,这个错误不是编译器错误!如果我在 Visual Studio 中进行调试,网站会正常运行。此错误消息仅在我尝试发布时出现

【问题讨论】:

    标签: asp.net-core asp.net-core-3.1 asp.net-core-5.0


    【解决方案1】:

    您可以检查以下步骤来解决您的问题。

    1. 下载 NET 5.0 SDK here

    2. 您需要Visual Studio 16.8 或更高版本才能在 Windows 上使用 .NET 5.0。请确认您的 VS 版本。

    3. 包裹:&lt;PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /&gt;是 已过时,请删除项目文件中的引用。

    4. 清理并重建。

    【讨论】:

    • 全部完成,同样的问题。我有 NET 5.0 。如果我运行dotnet --version,它会显示 5.0.100。我在 Visual Studio 16.8.2 上。我实际上已经删除了那行代码(好地方),同样的问题!
    • 如果新建一个.netcore3.1项目,然后编辑成.net5并引用这些包,会不会出错?
    • 我尝试这样做,它在我的项目中运行良好。
    • 或者你可以新建一个.net5.0项目然后引用这些包,你可以试试。
    • 嗨@MyDaftQuestions,你解决了这个问题吗?
    【解决方案2】:

    真的很尴尬

    发布的目标框架仍设置为 .NET Core 3.1

    【讨论】:

      【解决方案3】:

      如果您尚未移至 5,则可以通过单击 nuget 中的版本下拉菜单来安装 microsoft.aspnetcore.authentication.jwtbearer 版本 3.1.x。

      【讨论】:

        【解决方案4】:

        首先我只是快速浏览了一下,我认为这可能与您有一些版本不支持 3.1 的库有关,这就是您收到错误的原因。

        但请确定:There is a Microsoft guide for this specific migration

        【讨论】:

        • 我正在从 3.1 迁移,并且在针对 3.1 时它们都运行良好
        猜你喜欢
        • 2021-04-24
        • 2021-02-27
        • 2021-05-14
        • 2021-03-04
        • 1970-01-01
        • 2018-01-14
        • 1970-01-01
        • 2019-06-24
        • 2020-12-17
        相关资源
        最近更新 更多