Can't update or install package: An item with the same key has already been added

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>

If any one is using net core and got this error use command prompt to get detailed error message.

Please run dotnet restore to find the conflicting versions.

Above command need to run form the folder where pjt file resides.

Ex:

 Unable to satisfy conflicting requests for '************': (>= 1.0.1)

 (via package/************ 1.0.22), ************ (>= 1.0.1)

 (via project/************ 1.0.0) Framework: 

 (.NETStandard,Version=v2.0)C:\Users\************\Source\************API.csproj]

Tags:

Nuget