Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading to .NET Core 2.0: PackageTargetFallback and AssetTargetFallback cannot be used together

When upgrading a project that is compiling and running fine on .NET Core 1.0 or 1.1, updating the target framework to .NET Core 2.0 (netcoreapp2.0) causes the build to fail with the following error:

 error NU1003: PackageTargetFallback and AssetTargetFallback cannot be used together. Remove PackageTargetFallback(deprecated) references from the project environment. 

What is the reason for this error and how can it be resolved to make the project build again?

like image 914
Martin Ullrich Avatar asked Aug 08 '17 13:08

Martin Ullrich


1 Answers

In .NET Core 1.0 and 1.1, it was needed to set PackageTargetFallback when referencing packages that are known to work on .NET Core but don't officially support it - e.g. PCL libraries or libraries built for the legacy dotnet framework moniker.

Due to this, the project (.csproj, .fsproj, ...) will contain a line similar to:

<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback> 

In most cases, this line can simply be removed and the project should build because .NET Core 2.0 already defines AssetTargetFallback to be net461 - meaning that any NuGet package that is compatible with .NET Framework 4.6.1 or higher can be used without additional configuration.

If this introduces more build / restore errors, change the line to:

<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> 

The reason for the change is that PackageTargetFallback is considered deprecated and should be replaced with AssetTargetFallback which behaves only slightly different.

The breaking change in the tooling is that netcoreapp2.0 and netstandard2.0 automatically set AssetTargetFallback which conflicts with any PackageTargetFallback value defined in the project file.

like image 138
Martin Ullrich Avatar answered Oct 02 '22 10:10

Martin Ullrich