In this entry, I'll be outlining the process that I use to make a copy of a Visual Studio.NET project or solution with then end result of two projects copies on my development machine, each of which points to it's own location in Visual SourceSafe.
Assumptions
This entry assumes that you are using Visual Studio.NET 2003, and Visual SourceSafe 6.0d; and are familiar with Visual Studio.NET's basic functionality, menu system, and Visual SourceSafe's UI and "Working Folder" functionality. It is also assumed that you are familiar with creating a "Web Application" in IIS, on an existing folder.
The Process
1) Check In Everything:
The first step in this process is to ensure that you have all of your files in your project or solution, checked in to VSS. This ensures that both the original copy of your project and the new copy will start from the same base. This also prevents lost data in case of tragic events happening during the rest of the process. Open VS.NET, then open the solution in question, and check in all of the files that you are working with.
2) Unbind Your Solution:
With your solution still open inVS.NET, go to the File menu, then Source Control, then Change Source Control. In this pop-up screen, you should see a listing of your solution file and all of the projects in that solution. Select the item at the top of the list, and click the "Unbind" button at the top of the pop-up window. If you recieve a confirmation message, click OK or Continue, or whatever is required to actually unbind the item. After you have unbound the item at the top of the list, it will be moved the bottom of the list automatically. Continue to unbind each of the items in the list, until no items are bound to VSS. Once you have completed this, you must click OK at the bottom of the pop-up window, or these changes will not take affect!
NOTE: Now that the solution is no longer bound to VSS, you are free to do whatever you wish with it, without fear of overriding any files in VSS (unless you chose to push changes back into the same folder structure in VSS). DO NOT WORRY about your files in VSS at this point - we have not deleted or removed anything from VSS. All of your project files and code are still in tact, safely tucked away in the VSS database. If you would like to confirm this, simply open the VSS UI program and traverse the folder structure to your where your project resides. You will see all of the files from your project, right where they should be.
3) Copy The Solution:
The process to copy the solution varies slightly, if you have any web projects in your solution. Additionally, if your entire solution consists of only 1 web project, you may follow
- Remove All Web Projects From The Solution: If your solution contains any web projects, right click on the project name and select "Remove". If any confirmation dialog boxes appear, click OK or Continue, to remove the project. Repeat for all web projects.
- Save The Solution And Close VS.NET. Not much to explain here. Just click the "Save All" button or menu option (or your preferred method of saving all items), and then exit out of VS.NET entirely.
- Open Windows Explorer, Copy & Paste Non-Web Projects: Assuming all the non-web projects in the solution are contained within a folder underneath of the solution file's folder, locate the root folder of your solution and simply Copy & Paste this to a new location. If you have projects spread out in various folders, you will need to copy each of the project folders to a new location, for the new solution.
- Copy & Paste Web Projects: If you removed any web projects in step 1, locate the folder that contains your web servers projects, and do a Copy & Paste on the web projects that you need, giving them a new folder name. Ensure that the pasted projects still reside in the web servers folder. Next, you will need to open your IIS admin tool (typically, Internet Services Manager) and create an web application on each of the web project folders that you just pasted. Failure to specify these folders as web applications will result in the project not being available to VS.NET or your website.
- Open New Solution In VS.NET: Using VS.NET, open the solution file that you created during the copy & paste process in step 3. I would highly recommend changing the name of the new solution file now, to avoid confusing as to which solution you are working with, in the future.
- If your solution contained references to projects that were not directly underneath the solution file's folder, you will need to manually remove those projects from the solution, at this point. Once you have removed them, right click on the Solution file in VS.NET's solution explorer, and select the "Add" menu, then click "Existing Project...". Locate the copies you made during step 3, and add each project to the solution in this manner
- Re-Add All Web Projects To The Solution: If you removed any web projects during step 1, you will need to re-add them at this point. Right click on the solution file, in VS.NET's solution explorer, and in the "Add" menu, click "Existing Project From Web ...". Locate each of your web project folders by typing in the address of your website, followed by the folder name. This is typically "http://localhost/myprojectname/". Add the .*proj file to your solution, for each of the web projects in question.
At this point, you should now have two copies of the solution on your system - the original solution, and the recently copied solution.
4) Re-bind The Original Solution To VSS:
Open the original solution file that you started with, in VS.NET. Click the File / Source Control / Change Source Control menu item. The pop-up window will still show that all of the items in the solution are not bound to VSS. Click the solution file in the list and then click the Bind button at the top of the pop-up window. If required, log into your VSS database when the login screen pops up. You should now see a "Choose Project From SourceSafe" window, listing all of the folders in your VSS database. Traverse the folder structure to find the original location of your solution file in VSS, and click the "OK" button. If you specified an incorrect folder, you will see red wavy lines underneath of the "Server Binding" column in the Change Source Control pop-up window. If you specified the proper folder, and your projects are setup underneath of the solution file's folder, you may get lucky and have VS.NET automatically locate the remaining server bindings for you. If not, you will need to click on each project that is not bound, and repeat the process of locating the project's VSS folder, to rebind it.
After completing this, your original solution should now be 100% back on track, bound to VSS. You can now close this solution, and hopefully not have to worry about it anymore.
5) Add The New Solution To VSS:
Open the solution file that you pasted and renamed in step 3, in VS.NET. (Note: None of the files in this solution should be bound to VSS, at this point. If any of them are, you should re-think the process you just went through and attempt to follow these steps again, with any modifications that you may need for your specific scenario.)
The only work that remains is to add this new solution, and projects, to a new location in VSS. I won't be detailing the process to add a solution and it's projects to VSS in this entry. That deserves a post entirely to itself, to ensure that everything is organized the way you want it, in VSS, not the way VS.NET thinks you want it.
-----------------------------------------------------------------------------
I hope you find this topic useful. I've personally spent hours on end battling this very topic, trying to ensure that the two solutions I am working on are bound to seperate locations in VSS. If you have any questions, comments, additions, corrections, etc., please feel free to contact me or register on my website and post a response in the blog comments or forums.