20

I have several interfaces and classes that I have in my business layer project and I want to move them into a brand new project. I am using ReSharper 4.5.2. Is there any way I can do that easily and with no pain? I know about the move type functionality, but it seems like it will only do it within the same project.

Pang
  • 9,564
  • 146
  • 81
  • 122
Dan Appleyard
  • 7,405
  • 14
  • 49
  • 80

3 Answers3

31

You can just drag and drop the files in the solution window, then use ReSharper to automatically add the references and fix any namespace issues.

I've done it - it's not as 1-operation as the move type operation, but it's still very fast.


FYI - ReSharper 5.0 Beta 2 now supports this, directly, by right clicking on a file in the solution window, and choosing Refactor > Move.

Pang
  • 9,564
  • 146
  • 81
  • 122
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • 1
    When i do that, it simply copies the file from the one project to another. Is that what happens for you? – Dan Appleyard Feb 25 '10 at 22:55
  • 6
    @Dan Appleyard: Hold down "shift" as you drag, and it will move the file instead of copying it. – Reed Copsey Feb 25 '10 at 22:56
  • 3
    Alternative workflow (at least with Resharper 7.1.1, don't know about earlier versions): Select the file to move in Visual Studio Solution Explorer then Ctrl+R, Ctrl+O. The Resharper Move To Folder dialog will open, allowing you to browse to the folder to move the file to. The folder can be in another project. Has the option of updating the namespace appropriately, and all references and using statements in other projects and files that point to the file being moved. – Simon Elms Apr 02 '13 at 19:42
5

In the current version of ReSharper, the Move to Folder refactoring handles this fine:

  1. Select the files in Solution Explorer or the type in the code editor.
  2. Open the context menu (right-click or press Context Menu on your keyboard).
  3. Select Refactor.
  4. Select Move.

It's not as convenient as drag-n-drop, but it still does everything in one operation across multiple files.

Sam
  • 40,644
  • 36
  • 176
  • 219
2

To Elaborate on the accepted answer & comments here there's a simpler way.

Like @Dan Appleyard stated, you can use SHIFT+Drag to "Move" the file instead of "Copy", this will also trigger (in ReSharper 5+) the new project to be added to the references where needed.

Once you've done this go to the folder the moved file is in and choose Right Click -> Refactor -> Adjust Namespaces. This will correct the namespace the files live in to match the project/folder structure and will go put all the required using directives in all the files in the entire solution.

Aren
  • 54,668
  • 9
  • 68
  • 101