TFPT – “An item with the same key has already been added.”

Mar 12, 2016 ALM, General
[Reading Time: 3 minutes]

This day I struggled into an issue with migrating a shelveset from one branch to another. Unfortunately, an error appeared, so I got stuck.

To migrate my shelveset, I use tfpt.exe, that comes with Microsoft Teamfoundation Powertools 2015. So, I first started with typing following command into a developer command prompt:
tfpt unshelve migrate /source:”$/RootProject/SubProject/Branch1” /target:”$/RootProject/SubProject/Branche2” “shelvesetName”

Hint: To get this working, make sure you are calling tfpt.exe from the path, that is the root of you mapped path under beneath. In my case, I would go by “cd” to c:\Projects\RootProject\SubProject\Branch1

Now a dialog appears, that displays all shelveset details.image

From here you can go migrating this by clicking “Unshelve”. The next Dialog, that should appear, should display a bunch of unresolved conflicts, if any. These, you can either merge automatically ore by hand – it’s up to you. In my case nothing happened and console brought up an error – instead of the second dialog, saying “An item with the same key has already been added”. The content of this message is not really descriptive and meaningful… so what is the cause?

First I tried to figure out, where the root cause of this message was, but (honestly) then I felt more and more lazy, doing deep dive, so I considered looking up hints by the use of a Search engine Winking smile.

Here I found several solutions, ranging from adventure, over useless to senseless. But in general – luckily – there were recommendations for undoing pending changes in source (and often also for undoing these in target branch).

I tried some of these hints, but nothing worked. So I played a little bit around and found, that I was that far from a solution with undoing pending changes. It was not only undoing for source and target branch, but it was undoing everything in my Workspace to get that error message away and letting tfpt.exe work as expected.

As a conclusion, be sure, that you first make a “backup” of all pending changes in your workspace, by sending these to a temporary shelveset. Than you can undo all changes and migrate you desired shelveset to the target branche, that you chose before. After successful migration/move, you can restore the “Backup”-shelveset to your workspace. There you are…you moved a shelveset.

By Thomas

As Chief Technology Officer at Xpirit Germany. I am responsible for driving productivity for our customers by a full stack of dev and technology in modern times. But I not only care for technologies from Microsofts stack like Azure, AI, and IoT, but also for delivering quality and expertise with DevOps

4 thoughts on “TFPT – “An item with the same key has already been added.””
  1. This was the perfect solution when trying to unshelve into a different branch. I had files checked out in other solutions in the Workspace. Once shelved or checked in it worked like a charm. Thank you so much.

  2. Perfect. I wasted lot of time trying to merge my changes with no luck. You saved me another day. Thank you so much.

Leave a Reply to Kamesh Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.