Upgrading from ASP.NET Core 2.2 to 3.0
Asked Answered
S

2

28

I have an ASP.NET Core project with following csproj configuration:

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

I want to upgrade the project to <TargetFramework>netcoreapp3.0</TargetFramework>. Upon doing so, however, I get following warning:

C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\ Microsoft.NET.Sdk.DefaultItems.targets(149,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference.

What precisely is the solution to this? I tried to remove reference to Microsoft.AspNetCore.App, but that does not work. The code does not reference the shared framework.

Also, what does "Otherwise, the PackageReference should be replaced with a FrameworkReference" mean?

Scruff answered 30/9, 2019 at 8:24 Comment(1)
Migration instructions are available at the ASP.NET Core documentation site: Migrate from ASP.NET Core 2.2 to 3.0. They explain that this package reference isn't needed at all and packages that use the "Microsoft.NET.Sdk.Web" SDK automatically add it. Projects that target Razor need to add it as a FrameworkReferenceUnclench
D
32

If you are building a web project, please make sure the first line of your project file is:

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

In this case, it is automaticly included framework: Microsoft.AspNetCore.App. You don't have to include it again.

https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#framework-reference

If you are building a razor library not a web project, please make sure the first line of your project file is:

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

In this case, your library might dependend on some class in ASP.NET Core. You have to add this:

  <ItemGroup>
     <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

Don't forget to add:

    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>

to <PropertyGroup>

If you are not building a razor library nor a web project, typically you don't need Microsoft.AspNetCore.App. If you can really make sure what you are doing and really need it , consider adding:

  <ItemGroup>
     <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>
Dispatch answered 30/9, 2019 at 8:34 Comment(5)
Mine is neither a web nor Razor project... its a plain class lib. So, the last suggestion worked. Thanks!Scruff
I simply right-clicked the Microsoft.AspNetCore.App package under Dependencies > Packages and selected removeTreadmill
Thanks. This works in .net core 6.0 as well. Was looking at sample code built in .net core 2.0 that no longer bulid.Impiety
Also find this link that discuss how to migrate to 3.0 to 6.0 learn.microsoft.com/en-us/aspnet/core/migration/…Impiety
By the way: This post is still working in .NET 5,6,7,8Dispatch
C
1

Updating the project file with the following fix it for me:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>My-secret</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
  </ItemGroup>

</Project>

Reference

Clean answered 18/11, 2019 at 12:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.