升级到.NET Core 2.0:PackageTargetFallback和AssetTargetFallback不能一起使用

Mar*_*ich 57 csproj nuget .net-core asp.net-core .net-core-2.0

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

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

这个错误的原因是什么,以及如何解决再次构建项目的问题?

Mar*_*ich 104

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

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

<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
Run Code Online (Sandbox Code Playgroud)

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

如果这会引入更多构建/恢复错误,请将行更改为:

<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Run Code Online (Sandbox Code Playgroud)

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

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

  • 谢谢,我在编辑器中打开了csproj并完全删除了<PackageTargetFallback>元素,就像你建议的那样,它运行得很好. (10认同)