Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 928
MyDaftQuestions Avatar asked Dec 01 '20 19:12

MyDaftQuestions


4 Answers

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.

like image 114
Golden Lion Avatar answered Oct 12 '22 03:10

Golden Lion


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.

like image 32
Yinqiu Avatar answered Oct 12 '22 02:10

Yinqiu


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

like image 4
MyDaftQuestions Avatar answered Oct 12 '22 03:10

MyDaftQuestions


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

like image 1
suranga upul Avatar answered Oct 12 '22 01:10

suranga upul