问题
Today, I received an excel file with two columns. I have to rename objects in a solution according to excel file.
First column contains "current name", second column contains "new name". More than 5000 lines there.
Currently it is VS2013 with Resharper, C# solution contains several projects.
How can I automate this process?
回答1:
Unfortunately recent versions of Visual Studio have lost macros (essentially: not enough people using them). Thus the easiest path is unavailable.
As the other answer notes (now deleted), doing this one name at a time with existing VS tools is possible, but clearly infeasible for 5000!
I would approach this by:
Look for other tools, even if they have a price the time saved is likely to be significant. If nothing found, try #2. Given a few months Rosalyn might be an option (or even a preview of it: you won't be putting this into production with customers I assume!).
Put together a simple search and replace in a script tool (eg. PowerShell: advantage of having access to the full .NET framework and inbuilt CSV support) to perform one substitution (and you'll need to decide to include or exclude comments and strings). Then repeat that for each renaming.
#2 is likely to need to few tries: false positives will be all too easy.
来源:https://stackoverflow.com/questions/20972666/mass-renaming-refactoring-in-c-sharp-project