Re-target .NET Core to net471, net 472
Asked Answered
F

2

13

My .Netcore 2.0 project can target net471. But when I upgraded to .NET 2.1, I can't retarget net471 or net472

Can I retarget in the latest version of .the NET core?

Severity Code Description Project File Line Suppression State
Error NU1202 Package Microsoft.AspNetCore.App 2.1.0 is not compatible with net471 (.NETFramework,Version=v4.7.1). Package Microsoft.AspNetCore.App 2.1.0 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) 

and

Severity Code Description Project File Line Suppression State
Error NU1202 Package Microsoft.AspNetCore.App 2.1.0 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.App 2.1.0 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) 
Favourite answered 19/6, 2018 at 4:25 Comment(5)
In the most of cases, this is because the version of .NET Core SDK or Nuget is out of date. So try to update the version of NugetMarcin
Microsoft.AspNetCore.App is the new one, come with Asp.net core 2.1Favourite
What the message said. AspNetCore.App is a metapackage targeting .net core 2.1. It is used so we dont have to reference dozens of smaller ASP.NET Core assemblies. If you want to retarget to .NET Framework you have to REMOVE AspNetCore.App and add the single packages which you need, i.e. Microsoft.AspNetCore.MvcFromm
Easiest way to do is, create a new empty ASP.NET Core project which targets .NET Framework 4.7.2, then copy the package references from it and replace the .AspNetCore.All (or .AspNetCore.All) package with these references as well as change the target platform in the csprojFromm
Thanks, @Fromm your solution works fine.Favourite
F
34

It looks like Microsoft.AspNetCore.App and Microsoft.AspNetCore.All packages only work with the netcoreapp2.0 or netcoreapp2.1 version.

Wanting to target .NET Framework i.e. net471, net472, you have to remove these packages and manually add the references.

In my case, I removed Microsoft.AspNetCore.App and added references as below.

<PackageReference Include="Microsoft.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" />
Favourite answered 19/6, 2018 at 17:10 Comment(1)
This solved my problem. I am targeting net48 and could not get it to work. From learn.microsoft.com/en-us/aspnet/core/migration/… I was given the impression that the reference to Microsoft.AspNetCore.App would work.Lexicography
R
1

Hung Quach's answer is right 99% right. However I found it was missing two packages. So below is the full .csproj including the two missing project refs:

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

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="2.1.1" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
  </ItemGroup>

</Project>
Rivkarivkah answered 27/4, 2020 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.