我已经在使用 DocumentFormat.Ooxml
包,并且还想使用 ClosedXml
,它依赖于同一库的旧版本,所以我得到:
PM> Install-Package closedxml
Attempting to resolve dependency 'DocumentFormat.OpenXml (= 1.0)'.
Installing 'DocumentFormat.OpenXml 1.0'.
Successfully installed 'DocumentFormat.OpenXml 1.0'.
Installing 'ClosedXML 0.69.2'.
Successfully installed 'ClosedXML 0.69.2'.
Install failed. Rolling back...
Install-Package : Already referencing a newer version of 'DocumentFormat.OpenXml'.
nuget真的有针对这种情况的解决方案吗?即使我可以进行程序集重定向(我在单元测试中总是得到混合结果),我在 Install-Package
上看不到 -Force
参数。
编辑:交叉发布在nuget discussion board上
最佳答案
目前没有计划允许将包的多个版本一次安装到单个项目中。这通常会导致冲突,因为需要引用 2 个具有相同名称的程序集(并且位于 bin 文件夹中)。
这里的问题是 ClosedXML 对 DocumentFormat.OpenXml 具有特定于版本的依赖关系。您可以联系 ClosedXML 的所有者,看看他们是否可以发布允许使用不同版本的 DocumentFormat.OpenXml 的新版本。
如果这不成功,那么您可以尝试通过执行以下操作来摆脱这种冲突:
- Install-Package DocumentFormat.OpenXml [到达起点]
- Install-Package ClosedXML -ignoreDependencies [安装它,忽略其依赖项]
这将导致绑定(bind)重定向添加到您的 app/web.config 文件中,如下所示:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.5631.0" newVersion="2.5.5631.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
然后您需要测试您对 ClosedXML 的使用,看看新版本的 DocumentFormat.OpenXml 是否真的可以与它一起使用。如果它有效,您肯定想让 ClosedXML 的所有者知道这一点(使用 www.nuget.org 上的包的联系所有者链接),以便他们可以继续使用允许的新版本更新包较新的 DocumentFormat.OpenXml。
关于.net - nuget 是否有一种解决方案来包含依赖于一个包的不同版本的包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21562479/