We all have experienced the effort and time it takes to rename a project in a solution. We have to update folder and file names, adjust namespaces, fix various references, and usually yell at our computer to make things work. All that work takes a lot of iterations and can be frustrating.
What if the IDE could do that work for us? The latest Rider 2018.3 EAP build comes with the rename project refactoring! Let’s now look at the details.
We will be looking at an ASP.NET Core 2.1 Web API solution that has a number of projects. Originally, the solution had one project that allowed data to be accessed and updated from a Microsoft SQL Server using the Entity Framework Core library. The name of the project is Chinook.Data. Now we want to add an additional project that demonstrates Dapper as the data access library. Let’s create a new .NET Core 2.1 Class Library project in the solution and name it Chinook.DataDapper. With this new project name, we decide that we need to change the original data project to have a distinct name. Let’s call it Chinook.MSSQLData (I know we should have called the refactored project name Chinook.DataEFCore but go along with me).
With the Chinook.Data project highlighted, we will invoke the refactoring shortcut Ctrl+Shift+R and choose the Rename refactoring (we could have also invoked the Rename refactoring directly using the Ctrl+R, R). Now we have the Rename dialog presented as shown below.
There are three options that can be performed with the renaming of the project. The first option is to have the project folder renamed to follow the updated project name. The second option covers changing the root namespace with the refactoring. That is still experimental so we will not perform that update currently. The third and last option is to have the refactoring find all references to the original project name in comments and string literals throughout the solution and change them accordingly. We will perform the first and third options with our refactoring.
The Project Renaming refactoring will change all references to the project. That will include the following:
- Rename project folder and project file (
- The solution file (
- Rename root namespace and fix all references in other projects to symbols in this project (after namespace was changed).
- Rename assembly name including text occurrences in
- All other projects’ project files (
*.csproj) in the solution that reference the project renamed.
- Fix linked files in other projects which point to original files in the project renamed.
- All Using directives in referring projects.
- Any class types that have the full namespace included for the class type.
- Rename other related files, like
.pdbthat contain references to the renamed project.
- Fix any C#, XAML or Razor code references to the renamed project. An example for XAML is:
xmlns:local="clr-namespace:WpfApplication;assembly=WpfApplication" <- assembly reference [to the project]
<Image Source="pack://application:,,,/WpfApplication;component/Image1.png" /> <- pack reference [to the project]
There is a lot of work behind the code editor going on and this work will make your life much happier with the new refactoring included in Rider 2018.3 EAP. You can find out more about all of the refactorings at your fingertips in Rider in the Online Help.
Download Rider 2018.3 EAP and give it a try! We would love to hear your feedback on these updates!