Renaming the containing project folder in VS.net under TFS

Viewed 43959

I have a vs.net project, and after some refactoring, have modified the name of the project. How can I easily rename the underlying windows folder name to match this new project name under a TFS controlled project and solution?
Note, I used to be able to do by fiddling with things in the background using SourceSafe ...

6 Answers

Just right click on the folder in TFS, and select Rename. Once you commit the rename, TFS will make the changes on disk for you. As Kevin pointed out, you will want to make sure that everything is checked in, because TFS will remove the old folder and everything in it, and pull down the renamed folder with the current version of the files in it.

One final note: You can't rename a folder that you haven't mapped, or that you haven't done a "Get" from. I don't know why, but TFS will disable the Rename option in these cases.

At least that's what happened to me, if I remember correctly.

You could just rename the project (.Xproj file and project folder) in TFS, delete the local folder structure and all of its contents, then do a get latest for the project. All of this depends the notion of your source repository is completely up to date and compilable.

Here are steps that worked for me in Visual Studio 2008 with TFS:

  1. Close solution.
  2. Rename project folders in Source Control Explorer (right-click -> rename). This duplicates code into newly named folders.
  3. Open the solution, and in Solution Explorer, remove the old folders/projects and add the new, properly named, duplicates, (on old projects, right-click -> remove, then on the solution, right-click->Add->Existing Project...)

OR: After step 2, you can open the solution's .sln file in a text editor, and manually update the project folder names. If you do this, you might need to manually check-out the .sln file to be sure your changes will be checked in (<- important!).

For Visual Studio 2019 and ASP.NET Core 2.2 I had to modify Scott Munro's answer slightly. Here's what worked for me:

Before you start: Check in all changes and make a backup of your solution.

  1. Rename the project using the Solution Explorer (i.e. right click the project and click rename).
  2. Rename the project folder in Source Control Explorer.
  3. Open your solution's .sln file in a text editor, and fix the file path. (Replace any references to "OldProjectName" with "NewProjectName").
  4. Reload your solution in Visual Studio.
  5. Find and replace all the old namespaces with the new project name.
  6. Done. Check in changes.

I had to do step 1 first in order to get the project to load after fixing the file path in step 3.

Related