【问题标题】:Dependencies error while installing packages with NuGet使用 NuGet 安装包时出现依赖项错误
【发布时间】:2014-03-22 14:21:16
【问题描述】:

我正在尝试在 Visual Studio 2010 上使用 NuGet 安装以下软件包

  • TweetSharp 2.3.1 版(需要 Newtonsoft.Json 5.0.6 版)

  • SharpMap 1.1.0 版(需要 Newtonsoft.Json 4.5.11 版)

使用以下简单的 NuGet 命令:

PM> Install-Package TweetSharp
PM> Install-Package SharpMap

但是在安装第二个软件包后,我收到以下依赖项错误:

Install failed. Rolling back...
Install-Package : Updating 'Newtonsoft.Json 5.0.6' to 'Newtonsoft.Json 4.5.11' failed. Unable to find a version of 'TweetSharp' that is compatible with 'Newtonsoft.Json 4.5.11'.
At line:1 char:16
+ Install-Package <<<<  SharpMap
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

有没有办法解决这个问题?提前致谢。

【问题讨论】:

    标签: nuget tweetsharp sharpmap


    【解决方案1】:

    问题在于 SharpMap 已将依赖项定义为完全正确

    NewtonSoft.Json = 4.5.11

    不大于或等于,但完全等于。最好的方法是联系包的所有者并要求他们放宽要求。由于这个问题中所展示的原因,它并不是很有用。

    但是,您可以尝试使用-IgnoreDependencies 开关:

    > Install-Package SharpMap -IgnoreDependencies
    

    只安装 SharpMap,因此您需要在之后显式安装所有其他依赖项(NewtonSoft.Json 除外):

    > Install-Package BruTile -Version 0.7.4.4
    > Install-Package Common.Logging -Version 2.0.0
    > Install-Package GeoAPI -Version 1.7.2
    > Install-Package NetTopologySuite -Version 1.13.2
    > Install-Package NetTopologySuite.IO -Version 1.13.2
    > Install-Package ProjNET4GeoAPI -Version 1.3.0.3
    

    但是,SharpMap 仍会寻找 NewtonSoft.Json 4.5.11,因此您需要在应用程序配置文件中添加程序集绑定重定向:

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json"
                              publicKeyToken="30ad4fe6b2a6aeed"
                              culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.6.0"
                             newVersion="5.0.6.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    可能有效,但我没有尝试过,因为最终,这将取决于你想如何一起使用这两个库。

    Json.NET 主要版本的变化表明 4.x 和 5.0 之间存在重大更改,因此如果 SharpMap 依赖于受重大更改影响的 Json.NET 4.5.11 的某些功能,则不会工作。

    但是,根据我的经验,使用较新版本的 Json.NET 和针对旧版本编译的库往往可以正常工作,因此值得一试。

    【讨论】:

    • 尽管我不必添加程序集绑定,但它的工作就像一个魅力!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    相关资源
    最近更新 更多