26

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?

Jeremy Caney
  • 4,585
  • 13
  • 32
  • 54
Abhi
  • 1,446
  • 2
  • 13
  • 25
  • 1
    Migration instructions are available at the ASP.NET Core documentation site: [Migrate from ASP.NET Core 2.2 to 3.0](https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio). 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 `FrameworkReference` – Panagiotis Kanavos Sep 30 '19 at 08:31

2 Answers2

28

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://docs.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>
Anduin
  • 1,982
  • 2
  • 13
  • 31
  • 1
    Mine is neither a web nor Razor project... its a plain class lib. So, the last suggestion worked. Thanks! – Abhi Sep 30 '19 at 11:39
  • 2
    I simply right-clicked the Microsoft.AspNetCore.App package under Dependencies > Packages and selected remove – mortenma71 Nov 04 '19 at 21:06
0

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

mparkuk
  • 449
  • 6
  • 14