无法安装 nuget 包; DNXCore 依赖混淆

Can't install nuget package; DNXCore dependency confusion

我正在尝试添加 NuGet 包 Naos.Packaging.Nuget to the VS2015 project 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 ==========

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

NuGet.Frameworks 3.3.0 have a dependency on 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,即使我引用它,它甚至会在输出 window 中显示重复的引用,但在安装 nuget 时看不到引用。依赖项太多,无法找到问题的根本原因。

还有一点:nuget 的下载量只有 147 次,所以这很可能是一个值得向作者报告的错误。

来自the docs:

2 Dependency Behavior - this allows you to configure how NuGet will decide which versions of dependent packages will be installed. There are five options:

a. Ignore - This is usually a bad idea, as a package has dictated that it dependends on other packages and will require their contents to operate. You may choose to skip installing those packages.

.../...

3 File Conflict Options - If the package or any of its dependent packages being installed match a file already on disk, how should NuGet handle it?

.../...

c. Overwrite All - NuGet will overwrite any matching files in your project with those from the package

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

之前

Removed package 'NuGet.Core.2.8.6' from 'packages.config' Successfully uninstalled 'NuGet.Core.2.8.6' from Naos.Deployment.Core

这可能意味着必须完成卸载和重新安装的工作,但它随后将允许 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

因此请卸载所有使用较低版本的依赖项。

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

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