【发布时间】:2017-12-23 00:46:51
【问题描述】:
考虑到它的依赖关系,为什么我不能在 .NET 4.0 项目中安装 Newtonsoft.Json?
我有一个针对 .NET 4.0 的 .NET 类库项目,它引用了 Newtonsoft.Json 4.5.6 NuGet 包。我想将 Newtonsoft.Json 升级到最新版本(v10.0.3)。这会失败,并在包管理器控制台上打印以下消息:
无法安装软件包“System.Net.Http 4.0.0”。您正在尝试将此包安装到以“.NETFramework,Version=v4.0”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。如需更多信息,请联系包作者。
安装的依赖行为是:“最低”。
看Newtonsoft.Json NuGet包的依赖关系显示:
.NETFramework,Version=v4.0 没有依赖关系
我是不是误解了什么?我希望它可以安装在 .NET 4.0 项目中。
完整的安装日志是:
Attempting to gather dependency information for package 'Newtonsoft.Json.10.0.3' with respect to project 'XYZ', targeting '.NETFramework,Version=v4.0'
Attempting to resolve dependencies for package 'Newtonsoft.Json.10.0.3' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Newtonsoft.Json.10.0.3'
Resolved actions to install package 'Newtonsoft.Json.10.0.3'
Removed package 'Newtonsoft.Json.4.5.6' from 'packages.config'
Successfully uninstalled 'Newtonsoft.Json.4.5.6' from XYZ Removed package 'System.Net.Http.2.0.20710' from 'packages.config'
Successfully uninstalled 'System.Net.Http.2.0.20710' from XYZ
Adding package 'Newtonsoft.Json.10.0.3' to folder 'c:\MAIN\packages'
Added package 'Newtonsoft.Json.10.0.3' to folder 'c:\MAIN\packages'
Added package 'Newtonsoft.Json.10.0.3' to 'packages.config'
Executing script file 'c:\MAIN\packages\Newtonsoft.Json.10.0.3\tools\install.ps1'...
Successfully installed 'Newtonsoft.Json 10.0.3' to XYZ Install failed.
Rolling back...
Package 'System.Net.Http.4.0.0' does not exist in project 'XYZ'
Removed package 'Newtonsoft.Json.10.0.3' from 'packages.config'
Adding package 'System.Net.Http.2.0.20710', which only has dependencies, to project 'XYZ'.
Package 'System.Net.Http.2.0.20710' already exists in folder 'c:\MAIN\packages'
Added package 'System.Net.Http.2.0.20710' to 'packages.config'
Package 'Newtonsoft.Json.4.5.6' already exists in folder 'c:\MAIN\packages'
Added package 'Newtonsoft.Json.4.5.6' to 'packages.config'
Removing package 'Newtonsoft.Json.10.0.3' from folder 'c:\MAIN\packages'
Removed package 'Newtonsoft.Json.10.0.3' from folder 'c:\MAIN\packages'
Could not install package 'System.Net.Http 4.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', 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.
========== Finished ==========
将 Newtonsoft.Json 安装到 .NET 4.0 项目中的唯一方法是使用依赖行为“忽略依赖”。
【问题讨论】:
-
您使用的是什么版本的 Visual Studio? Json.NET 10.0.3 有一个专门用于 .NET 4.0 的程序集,如果这是项目的目标框架,则没有依赖项,因此您应该能够将其安装到 .NET 4.0 项目中。
-
我用的是VS2015。
-
什么是 NuGet 版本?
-
NuGet 版本为 3.4.4.1321。
-
谢谢。我有带有 NuGet 3.5 的 Visual Studio 2015,我可以将 Json.NET 10.0.3 安装到面向 .NET 4.0 的类库中而不会出现任何错误。
标签: json.net dependencies nuget