I was given a simple task of moving the project folders inside a Visual Studio Solution to a different folder because even though we were using
Solution Folders feature of Visual Studio, on disk, there were a lot of folders and adding them inside the CI pipelines' path filters was a pain to add and maintain.
This solution was already a part of Git Source Control, had internal dependencies and I wanted to do this and commit my changes with minimal fuss.
Credits -- https://stackoverflow.com/a/6310570
Follow the below steps to move the projects -
Open CMD/PowerShell (I am on Windows...)
Create the nested folder structure to where you would be moving the folders. You can either use
mkdiror the Explorer to create new folders.
Now, at the root folder of the solution, type in
git mv <source_folder> <destination_location>
Before actually moving the folder, you can also add the
--dry-runswitch at the end to see what changes would be made and errors which might come (if any).
In case you get an error because permission was denied, ensure that the project is closed in Visual Studio. This happens especially with the Database projects.
Now, if you open the destination path, you will notice that the project folder has moved.
After doing this if you try opening the solution, Visual Studio will complain that it was unable to load the projects which is fine.
To fix this, you can either
a. Open the Solution File (.SLN) in Notepad and fix the paths in there
b. In Solution Explorer,
Removethe project and then right click on the Solution -> Add -> Existing Project -> Select the Project File at the new path.
After adding the projects, you would have to remove the
Project Dependenciesand then add them again.
Once you have re-added the dependencies correctly, your solution should build.