Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move an existing VS project between solutions?

Tags:

How do I move an existing project (the project's own files, other files which the project depends on, settings (including Additional Include Directories) and all) from one solution to

  • a new solution which doesn't yet exist
  • an existing solution?

I am using Visual Studio Community 2015.

I do not want to hack .sln files; I want VS to do it properly. .sln files contain IDs which I don't understand.

Each project should retain its present project-name.

I have several projects I would like to move, each of which has dependencies which are not part of the project itself, so an easy method would be nice.

I see Visual Studio move project to a different folder but it doesn't answer my question.

No item in the Project menu is relevant (that's where I'd have thought the relevant item would be, if there were one), or any other toolbar menu, or the menu that pops up when I click mouse button 2 on the project's entry in the Solution Explorer...

like image 209
Rosie F Avatar asked Oct 30 '17 09:10

Rosie F


People also ask

How do you move a project from one solution to another?

To add an existing project to a solutionIn Solution Explorer, select the solution. On the File menu, point to Add, and click Existing Project. In the Add Existing Project dialog box, locate the project you want to add, select the project file, and then click Open. The project is added to the selected solution.

How do I change the location of a project in Visual Studio?

In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.

What is the difference between a project and a solution?

A project is contained within a solution. Despite its name, a solution isn't an "answer". It's simply a container for one or more related projects, along with build information, Visual Studio window settings, and any miscellaneous files that aren't associated with a particular project.


1 Answers

Here's how I now do it --- thanks to a comment by HansPassant.

Creating a new solution

If the new solution doesn't yet exist, create it as follows:

  1. In Visual Studio, File>New>Project
  2. In the New Project form,
    a. In the upper-left pane, choose Installed>Other Project Types>Visual Studio Solutions
    b. In Name: enter the new solution's name sln
    c. In Location: enter the parent directory of the new solution's directory
    d. Then OK the form.

Moving an existing project, which is already in one solution, to another solution

I think of a project as being part of a solution (rather than projects being separate from solutions). Therefore, in my solutions, a project's directory is a subdirectory of that for the solution which contains the project.

  1. Cut the project's directory proj and paste it into the new solution's directory sln
  2. In Visual Studio, load sln (if not already loaded)
  3. In the Solution Explorer,
    a. Click mouse button 2 on the line Solution 'sln'
    b. In the pop-up menu, select Add>Existing Project
    c. Navigate to sln\ proj and select proj.vcxproj
    d. Click Open

How come I didn't see this before? Two things. One was that I expected the function to be on a pop-up made by clicking mouse button 2 on the Solution Explorer entry for the project. The other was I had never before created a solution as such --- only ever created a project, choosing an existing solution or "Create new solution" as the case may be. Not good UI, IMO, to hid the "create solution" functionality under "New Project". Once the new solution exists, Hans's method makes the rest of the task easy.

like image 156
Rosie F Avatar answered Oct 20 '22 12:10

Rosie F