in

Platinum Bay

Peace, Love and Visual Studio Team System

.NETicated

Renaming and Copying Projects and Solutions

A question was posed to me this evening about copying and renaming Visual Studio projects. It is a lengthy enough topic to explain, I thought I better write it down. So here goes:

Renaming Projects

Step 1: Renaming projects can be an interesting challenge for the uninitiated. It's not quite as simple as just renaming the project node in the Solution Explorer tool window. Renaming the project node doesn't change the assembly name or the root namespace or the physical project folder name. Let's take a look at how to do just that.

When you rename a project, most likely you will want to rename the output assembly and/or the root namespace for the project. To do this, right-click on the project node and choose Properties. You can also double-click on the Properties (C#) or My Project (VB) node.

If it is not already selected, click on the Application tab. You will see two textboxes at the top; Assembly name and Root namespace. Assembly name is the filename given to the project's output assembly. A class library with an assembly name of Class1 will output a DLL named Class1.dll. Root namespace is, as the name suggests, the root namespace used for the project.

You may wish to change both the assembly name and root namespace when renaming a project.

Step 2: Next, I usually like to rename the physical project folder. To do this, close the solution within Visual Studio (you may have to close Visual Studio as well) and browse to the project folder. An easier way to get to the project folder might be to open a project file, right-click on the file's tab, and choose Open Containing Folder, then closing the solution or Visual Studio if necessary.

When you are at the project folder, rename it to match the new project name. Next, re-open the solution in Visual Studio. Visual Studio will complain that it can't load one or more projects.

This is fine, click OK. You will notice that your project is grayed out. Select the unavailable project node, go to the Properties tool window, and you will see that the File path property is editable. Click the value to show the ellipsis, , and click the ellipsis button. The dialog should be in the solution path, so browse into the renamed project folder and select the project file (*.*PROJ). Now, right-click on the unavailable project node in the Solution Explorer tool window, and choose Reload Project. Now your project is renamed and re-integrated into the solution.

 

Renaming Solutions

The process of renaming solutions is much easier. Simply rename the solution in the Solution Explorer tool window, and rename to physical solution folder. After renaming the solution folder, I would recommend opening up the solution file (*.SLN) manually while you are there as Visual Studio's MRU (Most Recently Used) shortcut lists won't be updated.

Copying Projects

Copying projects into the same solution requires a bit more legwork, including digging into the project files (*.*PROJ) themselves. First, go into Windows Explorer, and make a copy of the project folder, giving it the new project name.

Next, open up the solution file (*.SLN) in notepad. For our ClassLibrary1 solution, the solution file looks like:

Microsoft Visual Studio Solution File, Format Version 9.00

# Visual Studio 2005

Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.vbproj", "{9ED830D5-77A8-453D-B1CF-02E310E45EB1}"

EndProject

We are interested in the Project section. Copy those two lines, starting with Project and ending with EndProject. Then paste the text below the EndProject in a new line. If I wanted to add ClassLibrary1 as a new project called ClassLibrary2, I would change those references on the second project lines. The result would look like:

Microsoft Visual Studio Solution File, Format Version 9.00

# Visual Studio 2005

Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.vbproj", "{9ED830D5-77A8-453D-B1CF-02E310E45EB1}"

EndProject

Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ClassLibrary2", "ClassLibrary2\ClassLibrary2.vbproj", "{9ED830D5-77A8-453D-B1CF-02E310E45EB1}"

EndProject

The final step is to go into the new project folder, ClassLibrary2, and rename the project file. In our case, to ClassLibrary2.vbproj.

That's it. Open Visual Studio, and enjoy.

Copying Solutions

Again, copying solutions is much easier. Simply copy the solution directory (the one containing the .SLN file, give it a new name, and rename the solution file. If you wish, you may also want to rename the solution node in the Solution Explorer tool window.

Conclusion

It is possible to rename and copy projects and solutions, though it is a very manual process. I think it would be helpful to have an option to sync directory names with project and solution names in Visual Studio. If I find the time, I would like to build a Visual Studio add-in that does this and takes care of a lot of these manual steps automatically and intuitively.

Published Jan 01 2008, 03:30 PM by Steve
Filed under: , ,

Comments

June 24, 2008 10:03 AM

Very helpful and clearly written article.  Thanks Steve!

John B.
 

August 18, 2008 11:17 AM

Thanks Steve, I came up with a better acronym for my project and I was stumped. Nearly settled for the original until I stumbled on this article.

Paul C
 

September 7, 2008 3:03 AM

Very helpful - highly appreciated!!!

Andi E
 

September 8, 2008 3:58 AM

You saved my butt.  LOL. thanks.

nwDUDE
 

September 24, 2008 11:56 PM

When renaming the folder used by a project, if other projects had references to the project being renamed, then I found that I also needed to manually modify the csproj files of those other projects to change the path of the project reference.

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews has been working as a developer for more than 8 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. He has firsthand developer experience with a variety of languages, including Java, VB, and .NET. Most recently, he has been immersed in SharePoint. He is currently employed at RDA Corporation in Philadelphia, PA, as a Software Engineer and a team member in the Architectural Guidance evangelism team. Steve is also an MTCS (x2), ICSOO, and .NET fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.