5
votes

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

4

4 Answers

4
votes

Really embarrassing

The target framework for publish was still set to .NET Core 3.1

enter image description here

3
votes

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.

0
votes

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.

0
votes

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.