How can I rename a project folder from within Visual Studio?
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 Visual Studio 2012), 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.)
- If the property is not editable (as in Visual Studio 2012), then open the
- 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:
- Assembly
- Default/Root Namespace
- 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:
AssemblyProductAttribute
AssemblyDescriptionAttribute
AssemblyTitleAttribute
This is straightforward in Visual Studio 2015 (possibly works in older versions)
- In Solution Explorer, right click on Main solution → Rename
- In Solution Explorer, right click on project (under solution) → Rename
- In Solution Explorer, double click, or right click on Properties → goto Application Tab, rename Assembly name and Default namespace to match.
- If you wish to also rename the namespace, open one of your class files. Right click the namespace → Rename.... This should search and replace all references to your namespace throughout the project.
- Close the project → rename the project folder.
- Edit the
.sln
file in Notepad, and change the path to the csproj, i.e.,fu\bar.csproj
→bar\bar.csproj
.