Safely rename a project folder Visual Studio

VISUAL STUDIO IDE

How to rename one or more projects inside solution explorer in Visual Studio.

Photo by Joan Gamell on Unsplash

Learning Objectives

Developers encounter lots of difficulties while renaming a project structure in a solution inside Visual Studio.

Renaming a project includes

  • Folder rename
  • Project name update in solution explorer
  • Namespace update throughout the project files

Prerequisites

Install latest visual studio community edition.

Summary Steps

  1. Close Visual Studio.
  2. Rename the folder(s) outside Visual Studio.
  3. Open the solution in Visual Studio, ignoring the warnings.
  4. Go through all unavailable projects and click “F4” key view project properties.
  5. Set the file path to the new folder location.
  6. Right-click > Reload project.
  7. Change the display name of the project. Right-click > Rename.
  8. To rename namespaces, check the optional step below for the full guide.

Getting Started

The article demonstrates the renaming process using the following project structure. Example renaming project name from “HealthChecksv1” to “HealthChecksv2”.

Step 1: Close Visual Studio

Close the project from Visual Studio that you want to rename.

Step 2: Rename folder

Go to the File explorer directory & rename the folder from “HealthChecksv1” to “HealthChecksv2,” as shown below.

Step 3: Open the solution file

Open the solution file in Visual Studio; a warning message will appear as shown below, click “OK.”

It means the Visual Studio is unable to load the project.

Step 4: Open Project properties

Click on the project name and press the “F4” key to open project properties. Now rename the file path as shown below.

Step 5: Reload project

Right-click on the project name & click reload the project. Then rename the project name as highlighted below & save. It will automatically rename the .csproj file.

Optional Step: Rename Namespaces

Select namespace in any of the .cs files, click “Ctrl R + Ctrl R,” and click Apply. Now an option will be available to rename in all files.


Thank you for reading, and I hope you liked the article.

Stay tuned on C#

View at Medium.com

Leave a comment