Mina Matta
Mina Matta

Reputation: 1064

Visual Studio 2015 (ASP.NET Core) Compilation error Error: Microsoft.DotNet.Common.Targets - An item with the same key has already been added

When trying to build asp.net core project after changing the project path to the solution. I got the following compilation error in my solution referring visual studio file at "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets"

Error: An item with the same key has already been added. Key: Data Namespace.ProjectName C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 241

https://drive.google.com/file/d/0B8pVTUXkCFSpdWNpNHN5Y01CRnM/view?usp=sharing

Upvotes: 3

Views: 2062

Answers (3)

Philippe
Philippe

Reputation: 4051

None of the previous answer worked for me, here is what did the trick:

  1. Delete the project.lock.json (not always required)
  2. Run dotnet restore --no-cache
  3. Run dotnet build (a build in VS at this point still failed but works on command line

After that, it should build fine in VS.

BTW, if you are using TFS, don't forget to add an *.lock.json entry to your .tfignore file.

Upvotes: 1

Lutando
Lutando

Reputation: 5010

A dotnet restore --no-cache can also work. The Visual Studio 2015 tooling is not fully baked yet so you will run into these problems from time to time. I usually run into them when I make major changes to project.json.

Upvotes: 5

Mina Matta
Mina Matta

Reputation: 1064

Delete "project.lock.json" file from project files and rebuild the project again

Upvotes: 13

Related Questions