Visual Studio move project to a different folder

前端 未结 15 2590
野的像风
野的像风 2020-11-30 18:41

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


        
相关标签:
15条回答
  • 2020-11-30 19:15

    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!!
    0 讨论(0)
  • 2020-11-30 19:16

    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.
    0 讨论(0)
  • 2020-11-30 19:17

    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.

    0 讨论(0)
  • 2020-11-30 19:22

    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.

    0 讨论(0)
  • 2020-11-30 19:25

    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!!! :-)

    0 讨论(0)
  • 2020-11-30 19:26

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

    0 讨论(0)
提交回复
热议问题