Nuget 包还原:目标上的 .Net 版本错误

Nuget Package Restore: .Net Version Error on Target

出于某种原因,在使用 TeamCity 构建我的应用程序时,它坚持要尝试安装 "System.Runtime 4.0.20"。

然后我收到以下错误:

[update] WARNING: Package 'System.Runtime 4.0.20' does not exist in project 'AkkaNeat.Tests.csproj' [20:04:08][update] Removed package 'System.Resources.ResourceManager 4.0.0' from 'packages.config' [20:04:08][update] Removed package 'System.Linq 4.0.0' from 'packages.config' [20:04:08][update] For adding package 'System.Runtime 4.0.10' to project 'AkkaNeat.Tests.csproj' that targets 'net45'. [20:04:08][update] Could not install package 'System.Runtime 4.0.20'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. [20:04:08][update] Process exited with code 1 [20:04:09][Step 2/4] Step Restore NuGet packages (NuGet Installer) failed

不明白为什么非要加包。在 Xamarin 和 Visual Studio 中,代理机器上的一切都构建良好。

我花了整整两天时间来弄清楚这个问题。我什至尝试过将对 System.Runtime 的不同版本的引用显式添加到 packages.json 文件中。 Nuget 还是坚持指定版本。

您尝试安装的包不支持您的项目所针对的 .Net 版本。要解决此问题,请将您的项目所针对的 .Net 版本更新为包 System.Runtime 4.0.20 支持的 .Net 版本(您提供的输出中未显示)。

第 1 步:查找软件包支持的 .Net 版本。

您可以通过 looking at the folder that it's installed under 找到您的 nuget 包所需的版本。如果它在文件夹 /path/to/lib/net46path/to/lib/net451 中,那么它们分别表示 .Net 4.6 或 .Net 4.5.1。

第 2 步:change your project's .Net version