Renaming projects the easy way – new refactoring in Rider 2018.3

Posted on by Chris Woodruff

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.

Invoking the Project Rename dialog

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 execution of the refactoring for project renaming

The Project Renaming refactoring will change all references to the project. That will include the following:

  • Rename project folder and project file (*.csproj).
  • The solution file (*.sln).
  • 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 AssemblyInfo.cs
  • 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 .dotsettings, .config, .pdb that contain references to the renamed project.
  • Fix any C#, XAML or Razor code references to the renamed project. An example for XAML is:

<Window x:Class="WpfApplication.MainWindow"
xmlns:local="clr-namespace:WpfApplication;assembly=WpfApplication" <- assembly reference [to the project]
<Grid>
<Image Source="pack://application:,,,/WpfApplication;component/Image1.png" /> <- pack reference [to the project]
</Grid>
</Window>

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!

Comments below can no longer be edited.

13 Responses to Renaming projects the easy way – new refactoring in Rider 2018.3

  1. Bradley Uffner says:

    November 21, 2018

    Any chance of this coming to ReSharper for Visual Studio?

    • Kelby says:

      November 21, 2018

      I second this question, it is one of my more common refactors.

    • Chris Woodruff says:

      November 21, 2018

      The refactoring is not available in ReSharper at this time. Much more difficult to do inside Visual Studio. We are looking at implementing this refactoring maybe for R# 2019.X. Thanks for asking.

  2. oxysoft says:

    November 21, 2018

    Hell yeah! It’s always been a pain before to rename projects or solutions.

  3. Laurent Kempé says:

    November 22, 2018

    Very nice improvement! This has always been a pain

  4. Dew Drop - November 26, 2018 (#2846) - Morning Dew says:

    November 26, 2018

    […] Renaming projects the easy way – new refactoring in Rider 2018.3 (Chris Woodruff) […]

  5. Anatoliy says:

    April 25, 2019

    Doesn’t work for me. For what am I paying monthly?

    • Chris Woodruff says:

      May 2, 2019

      Anatoliy – Can you give me some for details? Email me at chris [.] woodruff [at] jetbrains [.] com please.

  6. Anatoliy says:

    May 2, 2019

    Take a look here for details
    https://youtrack.jetbrains.com/issue/RIDER-27144

    • Chris Woodruff says:

      May 2, 2019

      Looks like the team found the bug and will be fixed in 2019.2. Thanks!

  7. David V says:

    March 16, 2020

    Hello,

    This is odd, I’m on 2019.3.4 and the Rename Project Folder is greyed out and I cannot check it, do anybody knows what could cause this?

    Thanks

Subscribe

Subscribe to .NET Tools updates