How to Relocate Visual Studio project (.sln) file

Visual StudioRelative Path

Visual Studio Problem Overview


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.

Visual Studio Solutions


Solution 1 - Visual Studio

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.

Solution 2 - Visual Studio

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

Solution 3 - Visual Studio

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

Solution 4 - Visual Studio

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!

Solution 5 - Visual Studio

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrock WoolfView Question on Stackoverflow
Solution 1 - Visual StudioEl CheiconView Answer on Stackoverflow
Solution 2 - Visual StudiosavageguyView Answer on Stackoverflow
Solution 3 - Visual StudioOlivier de RivoyreView Answer on Stackoverflow
Solution 4 - Visual StudioLawView Answer on Stackoverflow
Solution 5 - Visual StudiojrummellView Answer on Stackoverflow