Visual Studio move project to a different folder

Visual StudioVisual Studio-2008

Visual Studio Problem Overview


How do I move a project to a different folder in Visual Studio? I am used to this structure in my projects.

-- app
---- Project.Something
---- Project.SomethingElse

I want to rename the whole namespace SomethingElse to SomethingNew, what's the best way to do that (without manually going into .sln file)?

Visual Studio Solutions


Solution 1 - Visual Studio

Remove the project from your solution by right-clicking it in the Solution Explorer window and choosing Remove. Move the entire project folder, including subdirectories wherever you want it to go. Add the project back to your solution.

Namespace names is something completely different, just edit the source code.

Solution 2 - Visual Studio

I tried the suggestion to remove and re-add the project, but then fixing up dependencies can be a pain.

I use this approach:

  1. Move the project folder.
  • If the project is in source control, do the move using source control commands.
  1. Edit the solution file in a text editor. There should be only one path that you need to change.

Solution 3 - Visual Studio

  1. Close your solution in VS2012
  2. Move your project to the new location
  3. Open your solution
  4. Select the project that failed to load
  5. In the Properties tool window, there an editable “File path” entry that allows you to select the new project location
  6. Set the new path
  7. Right click on the project and click reload

Solution 4 - Visual Studio

Summary: rename-and-move in VS2019 with git, retaining git history, leveraging R# a bit, automatic dependent project reference updating (important for sln's with many projects, we have >200)

I have been using the following steps to rename-and-move C# projects in Visual Studio 2019. This process uses R# to adjust namespaces. The git history is retained by doing a "git mv" (avoiding add/delete history drop).

Two phases: 1) rename the project in place and 2) move the project.

(Uses tip from base2 re unloading projects.)

Rename

  1. VS | Solution Explorer | right-click project | Rename (e.g., Utils.Foo to Foo).
  2. VS | Solution Explorer | right-click project | Properties | change assembly name, default namespace and Assembly Information fields
  3. Do 1 and 2 for corresponding test project (e.g., Utils.Foo.Tests)
  4. VS | Solution Explorer | right-click projects (production and test) | Refactor | Adjust Namespaces
  5. XAML files that use the project may need to be updated (manually or with an appropriate global search and replace)
  6. Rebuild All
  7. Commit!! (to commit changes before moves)

Note: The folder in Windows Explorer remains the old name to this point (e.g., Utils.Foo). This is fixed in the move steps.

Move

This method: 1) retains git history, 2) leverages R# to adjust namespaces atomically and 3) updates dependent projects en masse (avoids tedious manual editing of dependent sln and csproj files).

  1. unload all the projects in the solution (so that removal of the target project does not trigger changes in dependent projects)

    VS | select all solution folders under the Solution | right-click Unload Projects

  2. move folders using git (so history is maintained)

a) open Developer Command Prompt for 2019

b) git status (to illustrate “nothing to commit, working tree clean”)

c) git mv the project e.g., git mv "C:\Code\foo\foo\Utils.Foo" "C:\Code\Foo"

d) git status to view/verify change

  1. remove the project

VS | Solution Explorer | select project | right-click | Remove (since all projects are unloaded, this will correctly NOT remove the references to it in dependent projects)

  1. re-add the project (to the new location in the tree in Solution Explorer)

a) VS | Solution Explorer | select target parent folder | right-click | Add | Existing Project

  1. reload all projects

IMPORTANT: Confirm that *.csproj files for dependent projects have been updated.

(VS | Team Explorer | Changes | double-click any dependent csproj listed | inspect-verify ProjectReference path change)

  1. Manually fix paths in the single moved *.csproj file

Use Notepad++ (or other text editor) to fix the paths. Often this can be done with a simple search-and-replace (e.g., ../../../../ to ../../).

This will update...

a) GlobalAssmeblyInfo.cs references

b) paths to packages

c) paths to Dependency Validation diagram files

d) paths to ruleset paths (e.g., <CodeAnalysisRuleSet>..\..\..\..\SolutionDependencyValidation\IgnoreWarnings.ruleset</CodeAnalysisRuleSet>)

  1. Close and re-Open the solution (to get the project references into good shape)

Save All, Close Solution, I prefer to delete bin and obj folders to be clean of history, Re-open Solution

  1. Validate

a) VS | Team Explorer | Changes

i) should see Staged Changes that reveal the files that moved ii) should see dependent projects (*.csproj) that were nicely updated review the csproj diffs and notice that the paths have been beautifully updated!! (this is the magic that avoids laboriously manually updating the csproj files using a text editor)

b) in Windows Explorer, verify old location is empty

c) Clean Solution, Rebuild Solution, Run unit tests, Launch apps in sln.

  1. Commit!!

Solution 5 - Visual Studio

What worked for me was to:

  1. Remove the project from the solution.
  2. Edit the project file with a text editor.
  3. Update all relative paths to the "packages". In my case I had to change ..\packages to ..\..\..\packages since I moved the project to a deeper folder.
  4. Load the project back into the solution.

Solution 6 - Visual Studio

I had the same problem. I solved with move the references and in less than 15 minutes, without change the references.

For me the solution was simple:

  1. Move your files where you need.
  2. Delete the folder with name .vs. Must be as not visible folder.
  3. Open the solution file (.sln) using a simple editor like note or notepad++.
  4. Change the reference where your file is, using the following structure: if you put your project in the same folder remove the previous folder or the reference ".."; if you put in a above folder add the reference ".." or the name of the folder.
  5. Save the file with the changes.
  6. Open the project file (.csproj) and do the same, remove or add the reference.
  7. Save the changes.
  8. Open the solution file.

Examples:

In solution file (.sln)

  • Original: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.UI", "ScannerPDF\PATH1.UI\PATH1.UI.csproj", "{A26438AD-E428-4AE4-8AB8-A5D6933E2D7B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.DataService", "ScannerPDF\PATH1.DataService\PATH1.DataService.csproj", "{ED5A561B-3674-4613-ADE5-B13661146E2E}"

    New: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.MX.UI", "PATH1.MX.UI\PATH1.UI.csproj", "{A26438AD-E428-4AE4-8AB8-A5D6933E2D7B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.DataService", "PATH1.DataService\PATH1.DataService.csproj", "{ED5A561B-3674-4613-ADE5-B13661146E2E}"

In project file:

  • Original:

    New:

    Original reference: ....\lib\RCWF\2018.1.220.40\TelerikCommon.dll

    New reference: ..\lib\RCWF\2018.1.220.40\TelerikCommon.dll

Solution 7 - Visual Studio

in visual studio comunity 2019, i did what Victor David Francisco Enrique says, but needed only to delete the .vs invisbile folder

Solution 8 - Visual Studio

It's easy in VS2012; just use the change mapping feature:

  1. Create the folder where you want the solution to be moved to.
  2. Check-in all your project files (if you want to keep you changes), or rollback any checked out files.
  3. Close the solution.
  4. Open the Source Control Explorer.
  5. Right-click the solution, and select "Advanced -> Remove Mapping..."
  6. Change the "Local Folder" value to the one you created in step #1.
  7. Select "Change".
  8. Open the solution by double-clicking it in the source control explorer.

Solution 9 - Visual Studio

Most easy way, which I found for myself

I tried multiple times till I found a working way.. For example you want to move your project from sln folder to mySource folder.

  1. Remove your Project: In the SolutionExplorer of Visual Studio select your Project you want to change the directory, Press Delete -> Project gets removed. It still remains in your sln folder.
  2. Copy it to your Path: In the windows explorer copy your whole project to your mySource folder. -> Now you are ready to include it.
  3. Include back your Project: In the SolutionExplorer of Visual Studio add Existing Project and select your project from mySource folder. -> Project is now back in your Solution.
  4. Adjust your Project References: Check every Reference in your Project. On your Project -> Dependencies -> Project -> you see your project references. If there is a yellow Warning sign on a project reference than is it wrong. Delete your project reference and add it new. enter image description here
  5. Rebuild your Project: and let it Run. Afterwards you can delete your project in the sln folder, which is not anymore in use.

That works. Have fun :)

Solution 10 - Visual Studio

In VS 2015

  1. Unload your project in the solution explorer
  2. Create a new solution
  3. Copy the projects to the new solution's folder
  4. Right click the solution, add existing project.
  5. If you use some framework such as MVC, you may need to add the reference in the reference manager.

Solution 11 - Visual Studio

I figured out this try this it worked for me.

In visual studio 2017 community edition it creates a project at this path "C:\Users\mark\source\repos\mipmaps\mipmaps" This will create a access to file is denied issue

Now, you can fix that this way.

close your visual studio process. Then, find your project and copy the project folder But, first make a Sub-folder Named Projects inside of your visual studio 2017 folder in documents. Next, paste the project folder inside of your visual studio 2017 Project folder not the main visual studio 2017 folder it should go into the Sub-folder called Projects. Next, restart Visual studio 2017 Then, choose Open project Solution Then, find your project you pasted in your visual studio 2017 Projects folder Then clean the Project and rebuild it , It, should build and compile just fine. Hope, this Helped out anybody else. Not to sure why Microsoft thought building your projects in a path where it needs write permissions is beyond me.

Solution 12 - Visual Studio

I wanted the changes in Git to be shown as moves/renames instead of delete & adds. So I did a combo of the above and this post.

mkdir subdirectory
git mv -k ./* ./subdirectory
# check to make sure everything moved (see below)
git commit

And adjust the paths of the projects and of the assemblies from the nuget Pkg's in the sln file via a text editor.

Solution 13 - Visual Studio

  1. Copy the project folder to new destination
  2. Remove your project from solution (Right-click the project in "Solution Explorer" and choose "Remove")
  3. Then add existing project to solution (Right-click the project in "Solution Explorer" and choose "Add" then "Existing project")
  4. Change path to "packages" folder in "YourProjectName.csproj" file (Open in notepad and change paths for linked packages)

Solution 14 - Visual Studio

This worked for me vb2019. I copied my source project folder. I then pasted the project, and renamed the the folder to whatever. In order to break the ties back to the source project folder, I temporarily renamed the source folder. I opened my destination project. The paths to the forms and modules were re-discovered in the local folder. I went through all my forms and modules to make sure they were working. I ran the project. I closed the project. I renamed the source project folder back to is't original name. I can open both projects at the same time without errors.

Solution 15 - Visual Studio

No sure why all answers have overlooked at the most simple solution. Just run the "Command Prompt app" (in the windows bar search for CMD and it will appear automatically)

then just type the following command (change the path where relevant for your own case:)

robocopy /E C:\Users\Peter\source\repos D:\Peter\repos

What robocopy does is to "copies file data from one location to another." and the "secret source" is the / E that means "Copies subdirectories. This option automatically includes empty directories."

Enjoy!!! :-)

CMD Promt

Solution 16 - Visual Studio

  • Close the solution and move your project to new folder/location

  • Re-open your solution

  • Project should be loaded with '+' sigh referring as non checked in part. All the files of the project will be shown as Renamed.

  • If not working after reopening right click on the project and click unload and then reload.

  • It worked in VS2019

Solution 17 - Visual Studio

Group related projects together using solution folders

See http://msdn.microsoft.com/en-us/library/vstudio/c6c756s6(v=vs.100).aspx

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
QuestionEgor PavlikhinView Question on Stackoverflow
Solution 1 - Visual StudioHans PassantView Answer on Stackoverflow
Solution 2 - Visual StudioIgor ostrovskyView Answer on Stackoverflow
Solution 3 - Visual StudioEmmanuelView Answer on Stackoverflow
Solution 4 - Visual StudiodthalView Answer on Stackoverflow
Solution 5 - Visual StudioGonzalo MéndezView Answer on Stackoverflow
Solution 6 - Visual StudioVictor David Francisco EnriqueView Answer on Stackoverflow
Solution 7 - Visual StudioBWS1986View Answer on Stackoverflow
Solution 8 - Visual StudioForchView Answer on Stackoverflow
Solution 9 - Visual StudioFredyView Answer on Stackoverflow
Solution 10 - Visual Studiocode4jView Answer on Stackoverflow
Solution 11 - Visual StudiomarkkView Answer on Stackoverflow
Solution 12 - Visual StudioBob LokerseView Answer on Stackoverflow
Solution 13 - Visual StudioAnother MiView Answer on Stackoverflow
Solution 14 - Visual StudioSandyView Answer on Stackoverflow
Solution 15 - Visual StudioPatricio LobosView Answer on Stackoverflow
Solution 16 - Visual Studiov.t.View Answer on Stackoverflow
Solution 17 - Visual StudioSmit PatelView Answer on Stackoverflow