57

I would like to move the Visual Studio solution (myProject.sln) file into a folder.

The problem with doing this is that all the relative paths in the project will break, how can you relocate the project without updating all relative paths inside the project manually?

Thanks.

Harrison Paine
  • 611
  • 5
  • 14
Brock Woolf
  • 46,656
  • 50
  • 121
  • 144

5 Answers5

103

Just click on the solution in the Solution Explorer and then click on "Save myProject.sln as..." in the File Menu. This will save your .sln in the folder that you choose without breaking the references.

El Cheicon
  • 4,716
  • 3
  • 29
  • 25
  • I think the additional work, using source control will be the same if he chooses to take another way, since he's changing the location of the .sln anyway. – El Cheicon Mar 09 '09 at 15:29
  • This worked for me, as I needed to do this in order to check into TFS source control. Of course, if it had already been checked in, moving might have proved more difficult. – Jay Sep 16 '11 at 05:12
  • Thanks, I was just looking for that now. – Max Feb 16 '12 at 20:39
  • I am using TFS and VS 2010. While performing the above mentioned procedure I encounter a message "You are trying to move the solution file itself to a different folder. Please unbind the solution file from source control before attempting this operation". I believe unbinding might lead to system instability. What are my options? – Kabeer Apr 12 '13 at 05:49
  • 4
    Still relevant in VS2015. Thanks! This tip saved me from what would end with a massive brain tumor. – Steven Liekens Aug 06 '15 at 14:43
  • 1
    @Kabeer, no problem with unbinding the solution from source control. I did that, saved the .sln file where I wanted it. Then if you close the solution and reopen, Visual Studio will detect the solution is not bound and will ask you if you'd like to bind it. Do so and you are all set. (I ran on VS2015) – PBMe_HikeIt Mar 08 '16 at 16:28
  • Minor note: this doesn't remove the old .sln file, so you will have an obsolete duplicate in the old location. You can probably delete it (I haven't tried), but you don't need to. – Malcolm Aug 30 '19 at 19:32
  • "Save myProject.sln as..." does not exist in VS 2019 – jameshfisher Apr 09 '20 at 16:05
  • 3
    @jameshfisher Yes, it does, but as stated, you have to select the solution first in the Solution Explorer - it's a general "Save As..." command that applies to any single file, project or solution that is currently selected. – M Kloster Jun 18 '20 at 12:48
  • 2
    @jameshfisher Yes, it does, but at least in VS2022 it is not in right click menu; it is in a File menu sub entry. – Marcelo Scofano Diniz May 13 '22 at 17:41
4

To complete jrummell solution: after editing the *.sln file with the nodepadd, you certainly will have to delete the *.suo files that contains a deprecated cache.

Note that *.suo files are hidden files in windows 7 (so by default, you do not see it in your explorer).

Olivier de Rivoyre
  • 1,579
  • 1
  • 18
  • 24
4

With source control this is a little tricky. I just needed to move my solution .sln file up one level for easy access while maintaining source control history. I followed the advice of the previous posts but ran into a situation where TFS wanted to move all my projects with the solution. I accomplished this task using a combination with the following steps:

  1. Make sure solution is not open.
  2. Un-map solution from local drive.
  3. Right click Solution (.sln) in Source Control Explorer and select Move as mentioned above. Set the path of the new folder and select OK.
  4. Checkin that change.
  5. Checkout solution .sln and then edit the solution in notepad. You will see that the projects are assigned guids and there are file paths to the projects. You need to change all of those paths relative to where your new solution file .sln resides. Be sure and use double slashes for unique names and paths:

GlobalSection(TeamFoundationVersionControl) = preSolution

SccProjectUniqueName1 = MyNewFolder\\MyProject.Common\\MyProject.Common.csproj

SccProjectTopLevelParentUniqueName1 = MySolution.sln

SccProjectName1 = MyNewfolder/MyProject.Common 
SccLocalPath1 = MyNewFolder\\MyProject.Common

Check-in and re-map solution to local drive. This worked for me. Hope it helps!

Law
  • 359
  • 2
  • 12
4

open the .sln file inside notepad or similiar, near the top it has the relative base path - modify that to suit your needs.

savageguy
  • 1,535
  • 2
  • 13
  • 18
0

You can update the relative paths to each project in a text editor.

jrummell
  • 42,637
  • 17
  • 112
  • 171