Moving files between projects in TFS

by Alex Meyer-Gleaves 28 January 2009 - 6:25 PM

Team Foundation Server I came across a knowledge base article by Microsoft Support that describes how to move files between projects in TFS in a way that keeps their history. In short, to keep your history you need to perform the move in the Source Control Explorer and then fix up your project files. Performing the move in the Solution Explorer causes the project files to be updated immediately, but the history will not be kept because it results in a delete and add operation.

Strangely, the article recommends that you perform the move and check in your changes before fixing up the affected projects. That would put your version control database into an invalid state, and anyone who performed a Get Latest Version would find themselves with a solution that does not compile.

You can easily perform all the actions required to complete the move in one Change Set. These are the steps I find work well for me:

  1. In the Solution Explorer, right-click the files (or folders) you want to move and select Exclude From Project. This will check out the project file and remove any references to the items you are about to move.
  2. Use the Source Control Explorer to move the items to the new location. The moved items will be checked out and have a pending rename operation.
  3. Back in the Solution Explorer, go the the project you moved the items into and click the Show All Files button.
  4. You will now see the items you moved marked with a plain white document icon. Right-click the items and select Include In Project. This will check out the project file and add a reference to the items you moved.
  5. In your Pending Changes window you will see the two project files have edit operations pending, and the moved items have a rename operation pending.
  6. Make sure the solution builds, your unit tests pass and that the changes look correct in your favourite diff tool.
  7. Check in your Pending Changes. These changes will all go into one Change Set and your version control database will never be in an invalid state. You will of course also have kept your history.

This simple process allows you to keep your source control operations atomic while ensuring you keep your valuable history.

Tags: ,

Development Tools

Comments (7) -

Jonas
Jonas
12 October 2009 - 10:21 AM #

Step 1 makes the item get its Move menu option greyed in TFS for me, so I can't apply step 2. Frown

Reply

Alex Meyer-Gleaves
Alex Meyer-Gleaves
13 October 2009 - 4:23 AM #

Hi Jonas,

If you multiple workspaces configured on your machine, make sure the correct one is selected in the Source Control Explorer. Also, make sure the selected workspace has a working folder mapped that includes the folder containing the file to be moved.

Cheers,

Alex.

Reply

Morten
Morten
26 November 2009 - 12:21 PM #

If what Alex said didn't help Jonas, you should try to move one file at a time (that's what I had to do)

Reply

Aaron
Aaron United States
20 June 2011 - 1:27 PM #

VS2010 seems to have made this more difficult by trying to be more helpful.
Exclude from Project also sets up a pending delete of the file.
Undoing that puts the file back in the project!

Can't see how to do this now ...

Reply

Sander
Sander Belgium
30 June 2011 - 10:07 PM #

To exclude files in VS 2010 you can use one of the workarounds listed here:

connect.microsoft.com/.../vs-2010-exclude-from-project-deleting-files-from-source-control

Reply

Alex Meyer-Gleaves
Alex Meyer-Gleaves Australia
1 July 2011 - 2:01 PM #

Thanks Sander. I have voted for the issue on Connect. A better workaround would have been nice. I'm looking forward to a proper fix.

Reply

kindler chase
kindler chase United States
13 April 2012 - 4:15 AM #

With VS 2010 SP1, you can just move the file in the TFS Explorer. The history is maintained, albeit a bit obtuse. When the file is moved, the history only looks like one line. However, there is an arrow to the left of the history row that will expand and you can view all the previous history.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About the author

Alex Meyer-Gleaves I'm a Technical Architect living in Australia (that island like continent in the southern hemisphere). I love Microsoft .NET and C#. I hate early mornings, slow drivers and Lotus Notes.

Twitter

Google Shared

 

Month List

Recent Comments

Comment RSS

Links

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010