Using ReSharper to adjust namespaces across multiple files

By James Fisk

I’m currently working on a project that has a large amount of files and projects, as you can imagine managing all those files and projects can get a little unwieldy.  We as a team realised this, and decided to take some time out in order to reduce the amount of projects.

Now one of the tasks I was asked to do was to merge a number of the core projects into one project, this involved moving around 50+ files into the project that we were merging into.  So, with my task assigned to me I gallantly completed the task by simply moving the required files into the project, and hey presto job done.  Or was it?

As you may know that good development practice in .NET requires the developer to ensure that the namespace follows the directory structure from project root down to the file. Now moving the files was ok, but the job was half done, the namespaces did not match the dir structure of the files new location.  Ok I thought, I’ll just update the namespaces, but there was a lot of files 50+ files.  Ok I could just use find and replace, but that means I could screw it up because it requires my intervention.

What I needed was a addin that detects the incorrectly specified namespaces in the files, then when you have confirmed that you wish the files to be corrected, it’ll not only update the namespaces, and as a bonus it’ll update all the references, usings and clean up the code as well.  Funny enough there is such an addin, and it’s called (drum role) Resharper.

What you can do is select the offending files in the solution, either by right clicking on the selected files, or by right clicking on a project or solution folder in the solution, and then by selecting the menu item Refactor->Adjust Namespaces, you’ll then be presented with a wizard detailing the files that have been detected, clicking next will start the process.  After a while all the files and references will be updated, leaving you to save all the files afterwards (by default the wizards opens the files it has changed).

Now, this is just the tip of the iceberg regarding Resharper, it is a very powerful addin, not cheap, but well worth it in helping to speed up development, I recommend that you download the trial and give it a go, it supports VS 2008, VS 2010 and also VS 2003 as well.



categoriaUncategorized commento dataJuly 15th, 2010

About... James Fisk

This author published 12 posts in this site.

Share

FacebookTwitterEmailWindows LiveTechnoratiDeliciousDiggStumbleponMyspaceLikedin

Leave a comment