Using Visual Studio 2019 Version 16.6.0 Preview 2.1 - I have a solution with two projects:
Project A - Has a nuget package dependency Package1
Project B - Has a project reference to Project A
I now also require that Project B include the same nuget package dependency Package 1
When i attempt to install the package I get an error "An item with the same key has already been added".
I have seen a few posts that discuss this, but no definitive solution. For debugging purposes I want to keep Project A as a project reference for Project B. Any idea how I can solve for this?
Project Reference & Nuget Package Reference Conflict - Key with same name already exists
First, try to remove the Project Reference of Project A
in Porject B
,then Install Package in Project B and then add the Project Reference of Project A in Project B.Check if it works.
If not, I think there are some different conflicting versions of a nuget package in your Project. See this similar issue. You should remove the duplicate packages. Try these:
1) if you use Packages.config
, you should check whether there are two duplicate packages like these:
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
Delete the old one and remain the latest one. At the same time, check your xxx.csproj
file and delete the duplicate nodes.
2) delete bin
,obj
folder of Project A and Project B
3) clean local nuget caches and delete the packages folder under your solution(xxxx\Projects\MyProjName\packages
).
After that, run update-package -reinstall
under Tools
-->Nuget Package Manager
-->Package Manager Console
.
Do both on Project A and Project B.
4) and then to install Package 1
on Project B
to test whether the issue persists.