MyDaftQuestions
MyDaftQuestions

Reputation: 4701

Package Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 is not compatible with netcoreapp3.1 yet it's targeting net 5.0

I am migrating to .NET 5.0 from .Net Core 3.1.

I keep getting this error message:

Package Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / win-x86. Package Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 supports: net5.0 (.NETCoreApp,Version=v5.0)

I understand what it is saying, but I don't know why it is saying it.

My project targets .NET 5.0.

My csproj file looks like this:

<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>

I'm unsure why it's telling me about 3.1.

I manually removed the bin and obj folders, tried to update all nuget packages, and clean/rebuild the project, but I get the same issue each time.v

I am on Visual Studio 16.8.2.

EDIT

I should point out, the error is not a compiler error! If I debug in Visual Studio, the website spins up fine. This error message only occurs when I try to publish

Upvotes: 9

Views: 29396

Answers (5)

MyDaftQuestions
MyDaftQuestions

Reputation: 4701

Turned out it was this error, in that the target framework for publish was still set to .NET Core 3.1

enter image description here

Upvotes: 6

suranga upul
suranga upul

Reputation: 259

It's compatible with 3.1.17. try it enter image description here

Upvotes: 1

you can install the microsoft.aspnetcore.authentication.jwtbearer version 3.1.x by clicking on the version dropdown in nuget, if you haven't moved to 5.

Upvotes: 7

Jairo Blanco Aldao
Jairo Blanco Aldao

Reputation: 159

First I just took a quick look and I think it could be related that you have some libraries that the version doesn't support 3.1 and that's why you are getting the error.

But just to be sure: There is a Microsoft guide for this specific migration.

Upvotes: 1

Yinqiu
Yinqiu

Reputation: 7180

You can check the following steps to solve your problem.

  1. Download NET 5.0 SDK here.

  2. You need Visual Studio 16.8 or later to use .NET 5.0 on Windows. Please confirm your VS version.

  3. The package:<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> is obsolete, please remove the reference in the project file.

  4. Clean and rebuild.

Upvotes: 4

Related Questions