Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying a project in Visual Studio 2010

Is there an easy way to copy a project in Visual Studio 2010?

Copying a folder with project to a different path and opening it results in the following error.

Error

I'm interested only in solutions that would not involve more than 1 simple action. I'm creating a simple console project that I'm going to be copying hudreds of times, and not really a fan of going into settings and repeating multiple steps every time such a simple things needs to be done.

I'm using Visual C++ Express 2010. Note the project structure below. I created it as an Empty Project and added 1 single file main.cpp to it.

Project structure

The project was created using the settings.

The project in explorer looks like this.

There is a Copy Project function, but this means more than 1 manual action:

  • openning the old project;
  • pressing Copy on the menu;
  • closing the old Project;

Copying a parent folder of a solution would work, but that creates an unnecessary folder that I'd have to navigate in each copied project every time I need to access the copied project. I would like to avoid any unnecessary "pass-through" folders.

Note that create directory for solution was unchecked when the project was created, see the link above. If this was checked it would result in 2 unnecessary pass-through folders. There is a solution folder, folder where solution is created and a project folder. By unchecking the checkbox you get rid of project folder and project files are created in the solution directory, that still leaves the other 2 - I would like to have one for the reasons above.

like image 945
Leonid Avatar asked Dec 04 '11 21:12

Leonid


People also ask

How do you copy a project?

From the project, you can click on the title of the project to open up the details pane. From there, you can select “Copy project” from under the “…” menu. Your new project will be created with the same original project name with “- Copy” added to it so you can easily track the copied project.


1 Answers

It would be nice if you could just copy the vcxproj file itself -- but you cannot. The problem is that project files contain a GUID that Globally Uniquely IDentifies that project within Visual Studio; internally, projects are usually referenced by their GUID, not by their name. When you copy a project file, you are copying the GUID without changing it, which won't work. Note that both the vcxproj file and any sln files will reference the GUID, so you might want to avoid adding it to any sln files until after the GUID is changed.

The GUID section of the project file looks like this:

<ProjectGuid>{830DD595-EAD5-475B-9360-E4C2FD7CCC53}</ProjectGuid>

This line occurs precisely once in a valid vcxproj file. Any solution outside of the IDE for copying projects is going to have to change the GUID manually. The only way you're going to get this down to a single step is to write yourself a tool that changes the GUID -- although a search-and-replace with a good editor might be fast enough. You may find the function UuidCreate() helpful. Note that direct editing of the vcxproj file is also helpful if you need to change absolute paths to relative ones, etc.

Or, of course, you could just keep manually copying them using the tool within Visual Studio; the reason it exists is probably as a way to automate the GUID changeovers you need to do. I'll note that for our own projects, I frequently use Notepad for editing project files, though Notepad++ or UltraEdit are an even better idea.

like image 82
AHelps Avatar answered Oct 12 '22 18:10

AHelps