Ryu
Ryu

Reputation: 8759

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.

Upvotes: 3

Views: 691

Answers (5)

Ian Ringrose
Ian Ringrose

Reputation: 51927

You may be better of with a smaller number of projects that each have more files in each. It would not be that hard to write a C# programm the created a project file containing all your souce files.

Visual studio may or may not be able to cope with it then...

Upvotes: 0

John Saunders
John Saunders

Reputation: 161831

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.

Upvotes: 3

Matthew Vines
Matthew Vines

Reputation: 27581

If they all share the same business / data domain libraries, you can refactor that and then update the references in the projects.

More likely you want to create that business / data domain from these distributed projects. I don't know the details, but I'm willing to bet that smashing 20 solutions together won't help you in refactoring out common code.

  1. I would start small, and create a new solution that is your common application bits.
  2. Pull the obvious pieces of common code into that solution, and reference it's compiled dlls in your other projects.
  3. Review your projects and repeat until you have something resembling the structure you are looking for.

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1064254

What exactly is it you want to refactor? ReSharper is probably the best known tool for large scale refactorings... but whether it is appropriate depends on what you want to do.

You could always download the trial and give it a whirl...

Upvotes: 1

Victor Rodrigues
Victor Rodrigues

Reputation: 11741

I think there is nothing done to satisfy your need.

You could try slnTools to see how manipulate sln files, and merge them into one .sln file.

But I'm not sure if Visual Studio can handle well 500 opened projects.

Upvotes: 0

Related Questions