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?
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 legacydotnet
framework moniker.Due to this, the project (
.csproj
,.fsproj
, ...) will contain a line similar to:In most cases, this line can simply be removed and the project should build because .NET Core 2.0 already defines
AssetTargetFallback
to benet461
- 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:
The reason for the change is that
PackageTargetFallback
is considered deprecated and should be replaced withAssetTargetFallback
which behaves only slightly different.The breaking change in the tooling is that
netcoreapp2.0
andnetstandard2.0
automatically setAssetTargetFallback
which conflicts with anyPackageTargetFallback
value defined in the project file.