本文介绍了升级到 .NET Core 2.0:PackageTargetFallback 和 AssetTargetFallback 不能一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级在 .NET Core 1.0 或 1.1 上编译和运行良好的项目时,将目标框架更新到 .NET Core 2.0 (netcoreapp2.0) 会导致构建失败,并出现以下情况错误:

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?

推荐答案

在 .NET Core 1.0 和 1.1 中,引用已知可在 .NET Core 上运行的包时需要设置 PackageTargetFallback但不要正式支持它 - 例如PCL 库或为旧的 dotnet 框架名称构建的库.

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.

因此,项目 (.csproj, .fsproj, ...) 将包含类似于以下内容的行:

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

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

在大多数情况下,这一行可以简单地删除并且项目应该构建,因为 .NET Core 2.0 已经将 AssetTargetFallback 定义为 net461- 意味着无需额外配置即可使用任何与 .NET Framework 4.6.1 或更高版本兼容的 NuGet 包.

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>

更改的原因是 PackageTargetFallback 被认为已弃用,应替换为行为略有不同的 AssetTargetFallback.

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

工具中的重大变化是 netcoreapp2.0netstandard2.0 自动设置与任何 PackageTargetFallback 冲突的 AssetTargetFallback 项目文件中定义的值.

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.

这篇关于升级到 .NET Core 2.0:PackageTargetFallback 和 AssetTargetFallback 不能一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:23