Search code examples
visual-studioresharperautomated-refactoring

How to refactor a folder to a new project with the right dependencies in Visual studio?


I have a folder with sub-folders and multiple namespaces that is referenced in other projects. I want to refactor this folder into a new project.

Doing this manually will take a long time.

What is the most effective way to do this? Please could someone detail the steps?


Solution

  • 1º. Create the new Project \ Folder structure in the new solution (or project) and move the files manually to their respective folders.

    2º. Use the Visual Studio Find and Replace feature (filtering per folder ou per project) to batch rename the artifacts.

    Find and replace per project:

    Find and replace per project

    Find and replace per folder:

    Find and replace per folder

    When renaming, respect the convention of maintaining the namespace according to the folder. For example:

    Folder: ..src \ Foo.Domain \ Budget \ Repositories

    Namespace of artifacts contained in this folder:

    namespace Foo.Domain.Budget.Repositories
    {
    ...
    }