77

I have been doing some refactoring and reorganization and I have moved a bunch of files around.

I want to update each file so it has the "correct" namespace according to its new location. With ReSharper, I can go into each file and it shows me that the namespaces is incorrect but that way I have to do it each file at a time.

Is there anyway to update namespaces across every file in a folder or a project?

Chris
  • 5,882
  • 2
  • 32
  • 57
leora
  • 188,729
  • 360
  • 878
  • 1,366

3 Answers3

148

UPDATE: Anyone reading this question with R#5.0 and above should note that this is now a feature:

ReSharper -> Refactor -> Adjust Namespaces...

Iain Holder
  • 14,172
  • 10
  • 66
  • 86
  • 21
    +1 - select the files and right click -> refactor ->adjust namespaces, the option is greyed out if you are inside a file in the editor – Sam Holder Jan 04 '12 at 09:36
  • 12
    This feature alone is why ReSharper is worth its money. Total time saver when you are restructuring your solutions. – Martin Devillers Jan 10 '13 at 15:42
  • 5
    Probably also worth pointing out that you can scope a namespace refactor to a solution or project level simply by highlighting the appropriate container in Solution Explorer. – Chris Pickford Feb 21 '15 at 00:12
  • 3
    To expand even more on Chris Pickford's comment: as of ReSharper 9, you can also refactor namespaces at the folder or file levels. Select the appropriate container in Solution Explorer, right-click and select "Refactor > Adjust Namespaces". – Mass Dot Net Jun 27 '15 at 20:49
6

This isn't quite what you want to do ... but hopefully it's helpful.

Go to the class view, and rename the namespace using Ctrl+R,R. It will update that namespace in all the files/folders that it's used in. As long as your namespaces are consistant, it should acheive the same result as changing all the namespaces in a folder.

If your namespaces aren't consistant, and you're just tidying up then I'm afraid you've got a lot of clicking in front of you (or behind you as you've probably already done this).

Mark Worth
  • 926
  • 7
  • 6
1

I think that R# doesn't have this function. You can use CTRL-SHIFT-H to find&replace the string.

ema
  • 5,668
  • 1
  • 25
  • 31
  • can you do find /replace just in a folder? – leora Apr 26 '09 at 18:05
  • 1
    yes, you can do find/replace in a folder: in the Find In Files dialog, click the button with an ellipse next to the 'Look In' field, then specify your target folder(s) – stuartd Apr 26 '09 at 18:12