Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk Refactoring C#

I want to be able to refactor 500 projects at the same time.

I have about 20 solutions and I don't have a master solution with everything because I haven't figured out a way to auto generate it.

Any suggestions?

Thanks

Edit

I've tried slnTools from codeplex to generate a solution and visual studio pretty much took down the entire operating system. Not sure if it was the solution not being generated properly or if it was just a limitation of Windows / Visual Studio.

like image 369
Ryu Avatar asked May 11 '26 15:05

Ryu


1 Answers

To create the huge solution, you should be able to start with a macro vaguely like this:

    Dim d As New System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory())
    For Each f As System.IO.FileInfo In d.GetFiles("*.*proj")
        DTE.Solution.AddFromFile(f.FullName)
    Next
    DTE.Solution.Close(True)

Before you start the mega-refactoring, I'd suggest you use something like NDepend to analyze the dependency structure of the code, and compare it to your goals for refactoring. You'll only need projects in memory that will be affected by a particular refactoring. If you can limit the set that are needed, you'll greatly benefit.

If you can't get them all into memory, you should still be able to partition the work - you'll just have to repeat it. Consider the case where you've got a single class library that is used by ten other projects, and you want to refactor the public interface.

  1. Save a copy of the class library
  2. Load Project 1 and the class library, and do that refactoring. Close the solution.
  3. Restore the class library from the saved copy.
  4. Load Project 2 and the class library, and do that refactoring again. Close the solution.

etc. Finally, keep the last changed copy of the class library. If you really repeated the refactoring, all ten projects should be happy.

I'd also take the opportunity to refactor towards flexibility, so that you won't need to do this again. Accessing the class library through interfaces or facade classes can isolate you from changes in public interface.

like image 60
John Saunders Avatar answered May 13 '26 06:05

John Saunders