已添加具有相同密钥的项目

已添加具有相同密钥的项目

本文介绍了无法更新或安装包:已添加具有相同密钥的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在特定项目中,我无法更新或安装任何 NuGet 包.当我尝试使用 NuGet GUI 执行此操作时,它会执行一些操作,然后停止而什么也没说.当我尝试使用包管理器控制台执行此操作时,我得到以下输出:

In a particular project, I can't update or install any NuGet packages. When I try to do so using the NuGet GUI, it does some work and then stops without saying anything. When I try to do so using the package manager console, I get this output:

PM> Update-Package –reinstall EntityFramework
Attempting to gather dependencies information for multiple packages with respect to project 'SmartCentre', targeting '.NETFramework,Version=v4.5.2'
Update-Package : An item with the same key has already been added.
At line:1 char:15
+ Update-Package <<<<  –reinstall EntityFramework
    + CategoryInfo          : NotSpecified: (:) [Update-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

环境

  • Visual Studio Professional 2015 更新 1
  • NuGet 3.3.0.167
    • 删除packages文件夹
    • 重新启动 Visual Studio
    • 重新启动计算机

    推荐答案

    结果是 packages.config 文件有几个不同版本的重复项:

    It turned out that the packages.config file had a couple of duplicates with different versions:

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
      <!-- ... -->
      <package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
      <package id="Microsoft.AspNet.Web.Optimization" version="1.1.2" targetFramework="net40" />
      <!-- ... -->
      <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
      <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
      <!-- ... -->
    </packages>
    

    一旦我删除了重复项,问题就会停止发生:

    Once I removed the duplicates, the problems stopped happening:

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
      <!-- ... -->
      <package id="Microsoft.AspNet.Web.Optimization" version="1.1.2" targetFramework="net40" />
      <!-- ... -->
      <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
      <!-- ... -->
    </packages>
    

    这篇关于无法更新或安装包:已添加具有相同密钥的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:21