Refactoring a Company Name Change

Friday, September 24, 2010 / Posted by Luke Puplett /

When I began writing my app, my company name was a legacy to my IT consulting business, which was bought ‘off the peg’ as a semi-preformed company in 2001. Today my needs have changed and so close to release I needed to refactor over 80,000 lines of C# and all the XML stuff in-between with my new company name.

Today, my company name will be more visible and so I renamed the business to Evoq Limited. I had the foresight to use a codename, S26, as the root of my namespaces just in case refactoring would be an impossible job later; I wouldn’t have to look at the old company name forever.

As the Crow Flies

My theory was that all files are text files and so taking the direct route of doing a massive find and replace could work, as long as I covered all bases. It turns out that covering bases meant remembering to rename folders and files, too.

Here’s how I did it:

  • I first made sure all project code, i.e. all project folders, sat under a single folder on my local disk, Documents\Code for example.
  • In DOS I created a list of all folders: dir /ad/s/b | find /i “S26.Vuplan” > folders.txt
  • I then opened this in Excel and created a rename script. Instead of writing a batch file, I’ve often found hundreds of repeating similar commands are easier to put together in Excel.

Excel Script Build - Folders

Version on Flickr

  • Essentially, the Excel sheet looks for the position of the old text, S26.Vuplan, within the path.
  • It then has another column which tries to find the position of a \ backslash after the position of the old text.
  • This basically tells you whether the row represents the top level folder – we can skip this but there’ll be a lot of wasted renames of subfolders from and to the same name.
  • It then uses the SUBSTITUTE cell function to replace the old text with the new.
  • Then I use MID and the string position to extract just the folder name – this is because the DOS rename command wants a full folder path as argument 1 and just the renamed folder name as argument 2.
  • Finally, I build the DOS command by concatenating strings in the final column.
  • I then copy and paste the selected commands/cells into DOS which has the effect of submitting each cell value as a new DOS command.
  • After doing the folders, create a list of all the files that need renaming in a similar wat to above, Dir /s/a/b | find /i “S26.Vuplan” > files.txt
  • The above is repeated, except for finding top level folders.

Excel Script Build - Files

Version on Flickr

  • Copy and past the command cells into DOS as before.
  • Now enter each project folder and delete the bin and obj directories. This is to stop compilation errors due to using cached compiled assemblies with old stuff in them.
  • Open Visual Studio but don’t open a project.
  • Perform a Replace in Files on the code folder tree (do not choose to keep modded files open, else VS grinds to a halt under the impact of 100s of open files).
  • My rename did >13,000 replacements (S26.Vuplan > Evoq.Vuplan).
  • Now open your projects in reverse build order and makes sure they compile.

I experienced only minor problems, mostly because I didn’t delete the bin and obj folders until I realised what was happening. Once I sorted that, my ASP and WCF solutions all compiled right away! I was quite amazed.

(remember to make a backup or nine)




Post a Comment