Fastest way to update namespaces with ReSharper?

18,286

Solution 1

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

ReSharper -> Refactor -> Adjust Namespaces...

Solution 2

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).

Solution 3

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

Share:
18,286

Related videos on Youtube

leora
Author by

leora

Updated on August 18, 2020

Comments

  • leora
    leora almost 3 years

    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?

  • leora
    leora about 14 years
    can you do find /replace just in a folder?
  • stuartd
    stuartd about 14 years
    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)
  • Sam Holder
    Sam Holder over 11 years
    +1 - select the files and right click -> refactor ->adjust namespaces, the option is greyed out if you are inside a file in the editor
  • Martin Devillers
    Martin Devillers over 10 years
    This feature alone is why ReSharper is worth its money. Total time saver when you are restructuring your solutions.
  • Chris Pickford
    Chris Pickford over 8 years
    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.
  • Mass Dot Net
    Mass Dot Net almost 8 years
    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".