【问题标题】:Can't install nuget package; DNXCore dependency confusion无法安装nuget包; DNXCore 依赖混淆
【发布时间】:2016-01-27 17:11:47
【问题描述】:

我正在尝试将 NuGet 包 Naos.Packaging.Nuget 添加到 VS2015 项目 Naos.Deployment.Core。两者都是开源的。

我收到此错误:

Failed to add reference to 'System.Globalization'. Please make sure that it is in the Global Assembly Cache.

完整的输出粘贴在下面。

令人困惑的是,Naos.Deployment.Core 是一个 .net 4.5 项目。 Naos.Packaging.Nuget 也是如此。 Naos.Packaging.Nuget 依赖于 NuGet.Frameworks 依赖于 System.Globalization(据我所知,这是链中对 System.Globalization 的唯一依赖)。但是,这种依赖关系仅适用于 DNXCore 5.0 项目。

那么,为什么 DNXCore 会成为这里的问题?为什么我不能添加这个 nuget 包,我该如何修复它?

试过this approach,但没用。使用最新的 VS 2015(更新 1)和最新的 nuget。

Attempting to gather dependencies information for package 'Naos.Packaging.NuGet.1.0.5' with respect to project 'Naos.Deployment.Core', targeting '.NETFramework,Version=v4.5'
Attempting to resolve dependencies for package 'Naos.Packaging.NuGet.1.0.5' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Naos.Packaging.NuGet.1.0.5'
Resolved actions to install package 'Naos.Packaging.NuGet.1.0.5'
Removed package 'NuGet.Core.2.8.6' from 'packages.config'
Successfully uninstalled 'NuGet.Core.2.8.6' from Naos.Deployment.Core
Adding package 'Naos.Packaging.Domain.1.0.5' to folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Added package 'Naos.Packaging.Domain.1.0.5' to folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Added package 'Naos.Packaging.Domain.1.0.5' to 'packages.config'
Successfully installed 'Naos.Packaging.Domain 1.0.5' to Naos.Deployment.Core
Adding package 'NuGet.Configuration.3.3.0' to folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Added package 'NuGet.Configuration.3.3.0' to folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Install failed. Rolling back...
Package 'NuGet.Configuration.3.3.0 : ' does not exist in project 'Naos.Deployment.Core'
Removed package 'Naos.Packaging.Domain.1.0.5 : ' from 'packages.config'
Package 'NuGet.Core.2.8.6' already exists in folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Added package 'NuGet.Core.2.8.6' to 'packages.config'
Removing package 'NuGet.Configuration.3.3.0 : ' from folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Removed package 'NuGet.Configuration.3.3.0 : ' from folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Removing package 'Naos.Packaging.Domain.1.0.5 : ' from folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Removed package 'Naos.Packaging.Domain.1.0.5 : ' from folder 'C:\Users\suraj\Documents\GitHub\Naos.Deployment\packages'
Failed to add reference to 'System.Globalization'. Please make sure that it is in the Global Assembly Cache.
========== Finished ==========

【问题讨论】:

  • 这是一个 dnx 项目还是经典 C#?你是用nuget还是dnu来恢复的?
  • 两个项目都是经典的 c#。使用 nuget。
  • 您的项目是否针对 .net4.5(非客户端配置文件)?如果引用了System.Globalization,您是否尝试过先将其删除? nuget 是最新的吗?看来问题与NuGet.Configuration.3.3.0 有关,您是否尝试过使用nuget 安装该问题?
  • 这是一个标准的 .NET 4.5 - 我无法添加 System.Globalization,如果我手动更新 csproj 中的引用,它显示为丢失,但是在同一台机器上的相同 Visual Studio 版本对于同一框架,它不会显示为缺少的引用,并且在安装 NuGet 包时已正确添加。
  • @MsYvette 可以!我在 Twitter 上联系了 NuGet 团队,但没有收到回复。

标签: .net visual-studio-2015 nuget nuget-package


【解决方案1】:

Naos.Packaging.NuGet 1.0.7 依赖于 NuGet.Frameworks 3.3.0。

NuGet.Frameworks 3.3.0 依赖于System.Globalization 4.0.10。这就是它寻找 System.Globalization 的原因。

在尝试了一切之后,包括添加 System.Globalisation dll 作为参考。在不使用控制台的情况下,我使用了 VS 仪表板。

我决定ignore dependencies 并且还使用了overwrite conflicts 的选项,因此Naos.Packaging.NuGet.1.0.7 选项将自动成为首选。

安装日志:

Resolved actions to install package 'Naos.Packaging.NuGet.1.0.7'
Resolved actions to install package 'Naos.Packaging.NuGet.1.0.7'
Adding package 'Naos.Packaging.NuGet.1.0.7' to folder 'D:\VSpROJECTS\Naos.Deployment-master\Naos.Deployment-master\packages'
Added package 'Naos.Packaging.NuGet.1.0.7' to folder 'D:\VSpROJECTS\Naos.Deployment-master\Naos.Deployment-master\packages'
Added package 'Naos.Packaging.NuGet.1.0.7' to 'packages.config'
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to Naos.Deployment.Core.Test
Package 'Naos.Packaging.NuGet.1.0.7' already exists in folder 'D:\VSpROJECTS\Naos.Deployment-master\Naos.Deployment-master\packages'
Added package 'Naos.Packaging.NuGet.1.0.7' to 'packages.config'
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to Naos.Deployment.Core
========== Finished ==========

nuget 已安装,它会重新构建而不会出现错误。

所有其他依赖项都可以手动添加,日志中有一个列表,或者在 VS 中轻松检查。
经过更多测试后,我认为这是最好的选择。无论出于何种原因,即使我引用它,它也看不到 System.globalization,它甚至会在输出窗口中显示重复的引用,但在安装 nuget 时看不到引用。有太多的依赖关系无法找到问题的根本原因。

另外一点:nuget 只有 147 次下载,因此很可能是一个值得向作者报告的错误。

来自the docs

2 依赖行为 - 这允许您配置 NuGet 将如何决定将安装哪些版本的依赖包。那里 有五个选项:

一个。忽略 - 这通常是个坏主意,因为软件包规定 它依赖于其他包,并且需要它们的内容 操作。您可以选择跳过安装这些软件包。

.../...

3 文件冲突选项 - 如果正在安装的包或其任何依赖包与磁盘上已有的文件匹配,应该如何处理 NuGet 处理它?

.../...

c。全部覆盖 - NuGet 将覆盖您的所有匹配文件 项目与包中的那些

Spritely Recipees

在 InheritedTypeJasonConverter 中使用 System.Globalization

namespace Spritely.Recipes
{
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;

这也使用 System.Collections,在尝试独立添加 Naos.Packaging.NuGet 依赖项时也会引发错误。

如果我尝试单独引用这些,则会显示冲突,有两个引用。

包管理器也使用 System.Globalization:

namespace Naos.Deployment.Core
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.IO.Compression;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Xml;

Naos.Packaging.NuGet.1.0.7 安装到以下项目中没有问题:

Successfully installed 'Naos.Packaging.NuGet 1.0.7' to Naos.Deployment.Contract
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to Naos.Deployment.MessageBus.Handler
Successfully installed 'NuGet.PackageManagement 3.3.0' to Naos.Deployment.MessageBus.Contract
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to Naos.Deployment.CloudManagement
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to Naos.Deployment.Console

我已经就这个问题直接联系了 Naos,正在等待他们的回复。


以前的一些故障排除显示使用ignore dependencies 所需的绝望程度。

这是在一个新的 Visual Studio 项目中完成的。我误解了作者的初衷。

在哪里显示它是removing 包,它正在删除已安装但需要更新以与您正在使用的 Naos 包兼容的包。它没有做到这一点。这可能是由于某个包依赖于要删除的包。在本例中为“NuGet.Core.2.8.6”。或者它可能是您的文件中的一些轻微损坏。因此,您必须在尝试安装 Naos 之前卸载该软件包,并使用 Naos 所需的软件包版本对其进行更新,或者将其留给 Naos,然后添加它所需的依赖项。

这个问题是,如果您有依赖于“NuGet.Core.2.8.6”的包,您可能还需要卸载这些包。然后安装 Naos,然后重新安装依赖于 'NuGet.Core.2.8.6' 的其他包。

删除 NuGet.Core.2.8.6。在尝试安装 Naos.Packaging.NuGet 1.0.7 之前

已成功从“packages.config”中删除包“NuGet.Core.2.8.6” 从 Naos.Deployment.Core 卸载“NuGet.Core.2.8.6”

这可能意味着必须完成卸载和重新安装的工作,但它将允许 nuget 安装正确的依赖项。

然后进入目录并删除对它的所有引用。

这是我安装的过时版本:

PM> Install-Package Naos.Packaging.NuGet -Version 1.0.7
Attempting to gather dependencies information for package 'Naos.Packaging.NuGet.1.0.7' with respect to project 'WebApplication2', targeting '.NETFramework,Version=v4.5.2'
Attempting to resolve dependencies for package 'Naos.Packaging.NuGet.1.0.7' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Naos.Packaging.NuGet.1.0.7'
Resolved actions to install package 'Naos.Packaging.NuGet.1.0.7'
Removed package 'NuGet.Core.2.8.6' from 'packages.config'
Successfully uninstalled 'NuGet.Core.2.8.6' from WebApplication2
Adding package 'Naos.Packaging.Domain.1.0.7' to folder 'D:\Projects\WebApplication2\packages'
Added package 'Naos.Packaging.Domain.1.0.7' to folder 'D:\Projects\WebApplication2\packages'
Added package 'Naos.Packaging.Domain.1.0.7' to 'packages.config'
Successfully installed 'Naos.Packaging.Domain 1.0.7' to WebApplication2
Adding package 'NuGet.Configuration.3.3.0' to folder 'D:\Projects\WebApplication2\packages'
Added package 'NuGet.Configuration.3.3.0' to folder 'D:\Projects\WebApplication2\packages'
Added package 'NuGet.Configuration.3.3.0' to 'packages.config'
.../...
Added package 'Naos.Packaging.NuGet.1.0.7' to 'packages.config'
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to WebApplication2
Removing package 'NuGet.Core.2.8.6' from folder 'D:\Projects\WebApplication2\packages'
Removed package 'NuGet.Core.2.8.6' from folder 'D:\Projects\WebApplication2\packages'

这是我的成功,无需删除任何包:

Attempting to gather dependencies information for package 'Naos.Packaging.NuGet.1.0.7' with respect to project 'WebApplication1', targeting '.NETFramework,Version=v4.5.2'
Attempting to resolve dependencies for package 'Naos.Packaging.NuGet.1.0.7' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Naos.Packaging.NuGet.1.0.7'
Resolved actions to install package 'Naos.Packaging.NuGet.1.0.7'
Adding package 'Microsoft.Web.Xdt.2.1.1' to folder 'D:\Projects\WebApplication1\packages'
Added package 'Microsoft.Web.Xdt.2.1.1' to folder 'D:\Projects\WebApplication1\packages'
Added package 'Microsoft.Web.Xdt.2.1.1' to 'packages.config'
Successfully installed 'Microsoft.Web.Xdt 2.1.1' to WebApplication1
Adding package 'Naos.Packaging.Domain.1.0.7' to folder 'D:\Projects\WebApplication1\packages'
Added package 'Naos.Packaging.Domain.1.0.7' to folder 'D:\Projects\WebApplication1\packages'
Added package 'Naos.Packaging.Domain.1.0.7' to 'packages.config'
Successfully installed 'Naos.Packaging.Domain 1.0.7' to WebApplication1
Adding package 'NuGet.Configuration.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Configuration.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Configuration.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Configuration 3.3.0' to WebApplication1
Adding package 'NuGet.ContentModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.ContentModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.ContentModel.3.3.0' to 'packages.config'
Successfully installed 'NuGet.ContentModel 3.3.0' to WebApplication1
Adding package 'NuGet.Core.2.10.1' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Core.2.10.1' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Core.2.10.1' to 'packages.config'
Successfully installed 'NuGet.Core 2.10.1' to WebApplication1
Adding package 'NuGet.Logging.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Logging.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Logging.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Logging 3.3.0' to WebApplication1
Adding package 'NuGet.Versioning.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Versioning.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Versioning.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Versioning 3.3.0' to WebApplication1
Adding package 'NuGet.Frameworks.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Frameworks.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Frameworks.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Frameworks 3.3.0' to WebApplication1
Adding package 'NuGet.LibraryModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.LibraryModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.LibraryModel.3.3.0' to 'packages.config'
Successfully installed 'NuGet.LibraryModel 3.3.0' to WebApplication1
Adding package 'NuGet.Packaging.Core.Types.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Packaging.Core.Types.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Packaging.Core.Types.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Packaging.Core.Types 3.3.0' to WebApplication1
Adding package 'NuGet.Packaging.Core.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Packaging.Core.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Packaging.Core.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Packaging.Core 3.3.0' to WebApplication1
Adding package 'NuGet.Packaging.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Packaging.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Packaging.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Packaging 3.3.0' to WebApplication1
Adding package 'NuGet.Protocol.Core.Types.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Protocol.Core.Types.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Protocol.Core.Types.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Protocol.Core.Types 3.3.0' to WebApplication1
Adding package 'NuGet.Protocol.Core.v2.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Protocol.Core.v2.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Protocol.Core.v2.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Protocol.Core.v2 3.3.0' to WebApplication1
Adding package 'NuGet.Protocol.Core.v3.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Protocol.Core.v3.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Protocol.Core.v3.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Protocol.Core.v3 3.3.0' to WebApplication1
Adding package 'NuGet.Repositories.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Repositories.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Repositories.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Repositories 3.3.0' to WebApplication1
Adding package 'NuGet.Resolver.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Resolver.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Resolver.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Resolver 3.3.0' to WebApplication1
Adding package 'NuGet.RuntimeModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.RuntimeModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.RuntimeModel.3.3.0' to 'packages.config'
Successfully installed 'NuGet.RuntimeModel 3.3.0' to WebApplication1
Adding package 'NuGet.Client.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Client.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Client.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Client 3.3.0' to WebApplication1
Adding package 'NuGet.DependencyResolver.Core.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.DependencyResolver.Core.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.DependencyResolver.Core.3.3.0' to 'packages.config'
Successfully installed 'NuGet.DependencyResolver.Core 3.3.0' to WebApplication1
Adding package 'NuGet.DependencyResolver.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.DependencyResolver.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.DependencyResolver.3.3.0' to 'packages.config'
Successfully installed 'NuGet.DependencyResolver 3.3.0' to WebApplication1
Adding package 'NuGet.ProjectModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.ProjectModel.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.ProjectModel.3.3.0' to 'packages.config'
Successfully installed 'NuGet.ProjectModel 3.3.0' to WebApplication1
Adding package 'NuGet.Commands.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Commands.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.Commands.3.3.0' to 'packages.config'
Successfully installed 'NuGet.Commands 3.3.0' to WebApplication1
Adding package 'NuGet.ProjectManagement.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.ProjectManagement.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.ProjectManagement.3.3.0' to 'packages.config'
Successfully installed 'NuGet.ProjectManagement 3.3.0' to WebApplication1
Adding package 'NuGet.PackageManagement.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.PackageManagement.3.3.0' to folder 'D:\Projects\WebApplication1\packages'
Added package 'NuGet.PackageManagement.3.3.0' to 'packages.config'
Successfully installed 'NuGet.PackageManagement 3.3.0' to WebApplication1
Adding package 'Naos.Packaging.NuGet.1.0.7' to folder 'D:\Projects\WebApplication1\packages'
Added package 'Naos.Packaging.NuGet.1.0.7' to folder 'D:\Projects\WebApplication1\packages'
Added package 'Naos.Packaging.NuGet.1.0.7' to 'packages.config'
Successfully installed 'Naos.Packaging.NuGet 1.0.7' to WebApplication1

所以卸载所有使用低版本的依赖。

如果这不起作用,请告诉我。

【讨论】:

    【解决方案2】:

    从头开始重新创建 Naos.Deployment.Core 似乎已经解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 2019-04-15
      • 2014-02-15
      相关资源
      最近更新 更多