How to rename a Project Folder from within Visual

2019-01-01 13:49发布

My current solution for renaming the project folder is:

  • Remove the project from the solution.
  • Rename the folder outside Visual Studio.
  • Re-add the project to the solution.

Is there any better way?

30条回答
与君花间醉酒
2楼-- · 2019-01-01 14:27

I have written a small tool that automates all these steps. Also supports subversion for now.

Information about current releases can be found here Visual Studio Project Renamer Infos

Latests releases can now be downloaded from the Visual Studio Project Renamer Download Page

Feedback is much appreciated.

查看更多
倾城一夜雪
3楼-- · 2019-01-01 14:28

I use VS 2013 and TFS 2013.

I did it like this:

  1. Open Visual Studio, without opening solution itself, and use Source Control Explorer to find and rename folders for projects
  2. Double-click solution file in Source Control Explorer to open a solution.
  3. You get a question: "Projects have recently been added to this solution. Do you want to get them from source control?", and you choose Yes
  4. Now the Folder and project structure are there, but now files, so now you Get Latest Version from source control
  5. Try to build and commit changes.
查看更多
若你有天会懂
4楼-- · 2019-01-01 14:29

I just had to do this myself (using VS2010). As some folks have answered, the simplest step seems to be:

  1. Close the VS project.
  2. Open the .sln file and rename the project directory prefix for each of the .csproj occurrences.
  3. Save the .sln file
  4. Rename the actual project folder directory on your hard drive to match your changes in .sln file.
  5. Open the .sln (in VS) and rebuild
查看更多
墨雨无痕
5楼-- · 2019-01-01 14:29

1-Rename the project outside VS. 2-edit your_project_name.sln with a text editor, rename the path to the new path

查看更多
永恒的永恒
6楼-- · 2019-01-01 14:31

TFS users: If you are using source control that requires you to warn it before your rename files/folders then look at this answer instead which covers the extra steps required.


To rename a project's folder, file (.*proj) and display name in visual studio:

  • Close the solution.
  • Rename the folder(s) outside Visual Studio. (Rename in TFS if using source control)
  • Open the solution, ignoring the warnings (answer "no" if asked to load a project from source control).
  • Go through all the unavailable projects and...
    • Open the properties window for the project (highlight the project and press Alt+Enter or F4, or right-click > properties).
    • Set the property 'File Path' to the new location.
      • If the property is not editable (as in VS2012), then open the .sln file directly in another editor such as Notepad++ and update the paths there instead. (You may need to check-out the solution first in TFS etc.)
    • Reload the project - right-click > reload project.
    • Change the display name of the project, by highlighting it and pressing F2, or right-click > rename.

Note: Other suggested solutions that involve removing and then re-adding the project to the solution will break project references.

If you perform these steps then you might also consider renaming the following to match:

  1. Assembly
  2. Default/Root Namespace
  3. Namespace of existing files (use the refactor tools in Visual Studio or ReSharper's inconsistent namespaces tool)

Also consider modifying the values of the following assembly attributes:

  1. AssemblyProductAttribute
  2. AssemblyDescriptionAttribute
  3. AssemblyTitleAttribute

You may wish to vote for the Visual Studio team to automate this procedure.

查看更多
临风纵饮
7楼-- · 2019-01-01 14:31

I did the following:

  1. Rename the project from within vs2013. (optional/not needed)

  2. Export the project as a template.

  3. Close the solution.

  4. Reopen the solution

  5. Create a project from the saved template and use the name you like.

  6. Delete from the solution explorer the previous project.

In this point I tried to compile the new solution and to do so i had to manually copy some resources and headers to the new project folder from the old project folder. Do this until it compiles without errors. Now this new project saved the ".exe" file to the previous folder.*

So ->

  1. Go to windows explorer and manually copy the solution file from the old project folder to the new project folder.

  2. Close the solution, and open the solution from within the new project.

  3. Changed the configuration back to (x64) if needed.

  4. Delete the folder of the project with the old name from the folder of the solution.

查看更多
登录 后发表回答