3
votes

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

3

3 Answers

13
votes

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

5
votes

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.

1
votes

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.