升级到.NET Core 2.0:PackageTargetFallback和AssetTargetFallback不能一起使用 [英] Upgrading to .NET Core 2.0: PackageTargetFallback and AssetTargetFallback cannot be used together

查看:198
本文介绍了升级到.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.

此错误的原因是什么,如何解决使该项目重新构建? / p>

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中,需要设置 PackageTargetFallback 当引用已知可在.NET Core上运行但不正式支持的包时-例如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兼容的NuGet软件包无需其他配置即可使用Framework 4.6.1或更高版本。

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.0 netstandard2.0 自动设置 AssetTargetFallback 与项目文件中定义的任何 PackageTargetFallback 值冲突。

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不能一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆