rheone
rheone

Reputation: 1567

How to bulk refactor class / cs file names in a large TFS managed Visual Studio project

I'm currently working within a monolithic solution that is a conglomeration of several smaller projects and the result of many developers efforts. However, one of these efforts was not the creation of a standards document regarding naming practices for test classes. As such I have over 1500 individual test classes that may have a suffix of "Test", "Tester", or "Tests".

Is there a good way to batch rename all the *[Test|Tester].cs files within our solution to *Tests.cs taking into account the preexisting TFS and project file structure?

Upvotes: 2

Views: 298

Answers (2)

rheone
rheone

Reputation: 1567

The solution that seemed to work for me was to do a Find & Replace via a regular expression across targeted test projects within my solution.

In the standared Visual Studio Find and Replace Dialog

I searched for public\W+class\W+([a-zA-Z0-9-_]+)Test(er)?\b

and replaced with the captured group of public class $1Tests

within all files matching *Test.cs;*Tester.cs

Importantly, and for reasons unknown to me, if I didn't check the "Keep modified files open after Replace All" the find and replace would fail

eg:

magic search dialog

Once the find and replace operation was completed I used Resharper's Move Types Into Matching Files refactor function on the test packages in order to update references in both TFS and various project files.

Upvotes: 3

Daniel Mann
Daniel Mann

Reputation: 59037

Use a local workspace and your bulk renaming tool of choice. It doesn't have to be within Visual Studio. A local workspace will allow changes to the structure of the project to be made from any tool and still "noticed" by the pending changes window or tf.exe.

You'll still have to update the *.*proj files to take into account that the files have been renamed, of course.

Upvotes: 0

Related Questions