Recently, I needed to reorganize the folder that contained all of the projects under source control for a solution. The solution was started several years ago and the number of projects has steadily grown over the years and started polluting the root solution directory. I wanted to clean this up and move projects into sub-folders for their functional area, such as plug-ins, data/business, and common.
This seemed like a fairly trivial thing to do, but I quickly ran into problems. Most of these problems seemed to be related to the fact that the projects were under source control with TFS. After some trial an error, I came up with the following process:
- Load the solution that contains the projects that are moving.
- Remove the Source Control Bindings for any of the projects that are going to move. This can be accomplished by going to File > Source Control > Change Source Control. In the resulting window, select the projects that are going to move and click the “Unbind” button in the toolbar. This will update the solution file.
- Close the solution.
- Open the Source Control Explorer and navigate to the parent folder that contains the project to be moved.
- Right-click on the project folder and select “Move…”. In the resulting window, browse to the new location for the project.
- Navigate into the new project file location and checkout the “{projectName}.vspscc” file. If you don’t do this now, you will receive an error when you re-add the source control bindings later.
- Close Visual Studio.
- Using Windows Explorer, navigate to the root folder for the solution and delete the “{solutionName}.suo” file. This prevents Visual Studio from getting confused the next time you open the solution.
- Edit the “{solutionName}.sln” file and update the path to the new project file location. Just search for the project name and the update the portion of the line the points to the “*.*proj” file.
- Open the solution. At this point, any projects that reference the moved projects will be updated (checked out) to reflect the new location.
- Update the Source Control Bindings to rebind the projects that were removed at the beginning of the process (the unbound projects will be located at the bottom of the list) by selecting the project and clicking the “bind” button in the toolbar.
- At this point, the project will be highlighted with a red underline stating that there is an issue. This is because we haven’t checked our changes in yet so the server path doesn’t exist. This will be corrected soon.
- Rebuild your solution to make sure there are no side-effects. When I did this, I had to update a few references to shared DLL’s in the moved projects because the reference path was no longer valid.
- Commit your changes.
That’s it. Simple, right? ;)
There are some things you could do differently. For instance, instead of editing the solution file by hand, you could remove the project from the solution, perform the TFS move, then re-add the project to the solution. However, you will need to re-add the reference to the moved project in any projects that depended on it originally. For me, it was faster to just edit the solution file manually because this doesn’t remove project references and Visual Studio will update the dependant projects for me.
Happy Coding!
4 comments:
thanks a lot :)
worked a charm. surely this feature needs to go into VS/TFS!
Note for newer versions of VS:
File > Source Control > Advanced > Change Source Control
Really enjoyed this article.Much thanks again. Want more
azure online training in hyderabad
ms azure online training
Post a Comment