29

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...

Rosie F
  • 689
  • 1
  • 6
  • 10
  • 3
    In the Solution Explorer window, right-click and select Remove to remove a project from a solution. Right-click the solution (top node) and select Add > Existing Project to add a project to a solution. – Hans Passant Oct 31 '17 at 07:42
  • Thank you. Should I move the project's files from \ to \ before doing Add>Existing Project, or does Add>Existing Project do that automatically? (It would be untidy for the files to be in the old solution's directory-tree if the project is in the new solution.) – Rosie F Oct 31 '17 at 08:09
  • That is entirely up to you, VS doesn't care. The question you don't like tells you how to do that. – Hans Passant Oct 31 '17 at 08:15
  • @HansPassant I thought I'd ask, just in case the VS files \\.vcxproj* contained links to the source files in \, and the links would be broken if I just moved the source files. – Rosie F Oct 31 '17 at 08:21
  • @HansPassant Your method works for me! If you post it as an answer, I'll accept. – Rosie F Nov 05 '17 at 13:44
  • I have no idea what you actually needed to get unblocked. Just tell us what you did in your own post and accept it as the answer. – Hans Passant Nov 05 '17 at 13:47
  • @HansPassant OK. – Rosie F Nov 05 '17 at 13:49
  • A word of caution for Hans' answer - if you plan to Git your project, this might cause some problems as the project directory will exist outside of your solution folder. – stigzler Dec 27 '22 at 10:54

1 Answers1

29

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.

Rosie F
  • 689
  • 1
  • 6
  • 10
  • 5
    in VS 2019, for me, to create the empty solution i: 1) File | New | Project 2) In the search field type in "Solution". 3) this reveals "Blank Solution". – orion elenzil Apr 07 '20 at 23:14
  • For anyone else facing issues with moving a solution, ensure you aren't debugging at the time. The "Add Existing Project..." option won't be available. – Ian Dallas Jun 03 '20 at 16:07