views:

717

answers:

5

Hi all, I have a big ASP.NET project full of hard coded strings, that now have to be extracted to resources. Such strings can be found almost anywhere (in .cs files, .aspx files, .ascx files, etc.) and the amount of files is huge. What I'm looking for is a tool (or any way) to find all these hard coded strings in one shot and put them all together in the resource file, instead of me going manually through each file. Does anything like this exist?

Note: I'm aware that it would have been better to put the strings in resources straight away when they were needed the first time, but this is a 2 years old project where nobody really cared (typical example of "not my problem" philosophy).

Thank you very much.

UPDATE: I tried CodeRush (I couldn't try RGreatEx for obvious reasons), and I'm having difficulties using it. The main issue is that the strings I'm looking for are located mainly in .aspx files, and strings in those files don't have the "Refactor to resource" command available.

For example, I can have elements like this:

<dxwgv:ASPxSummaryItem DisplayFormat="{0}" FieldName="TOTAL" ShowInColumn="Total" SummaryType="Sum" />

The part I need to change is ShowInColumn="Total" and make it like ShowInColumn="<%$ Resources:PortalResource, Total %>". This is not a string assignment in a strict way, but an attribute assignment, so the "Refactor!" command of CodeRush doesn't appear.

My target is to find all of them in one shot and change them in a specific interface (i.e. like a localization tool) instead of looking for them one by one and manually creating the corresponding resource. Refactoring one by one inside each file would be an improvement, but still very time consuming...

A: 

If you have a look at DevExpress' CodeRush it has the functionaility you are looking for, you may need to automate it to do it a all in one shot.

It has a great deal more too!

Kindness,

Dan

Daniel Elliott
+1  A: 

Try RGreatEx. This is a plugin for ReSharper:

RGreatEx is the most powerful localizer and coding helper for Visual Studio. Once installed, it lets you localize .NET applications and produce safer code, saving up to 95% of time the developer usually spends on doing the same by hand. Empower yourself with time-saving refactorings, such as "Move to resource" and "Rename resource". The plug-in will automatically analyze string and resource usage and suggest moving strings to resources.

Anton Gogolev
RGreatEx is no longer available. Functionality will be integrated into R# 5.0.
The Chairman
A: 

Do you have ReSharper? Then you perhaps should wait for version 5.0. It will have RGreatEx (mentioned by Anton) functionality included. Read the thread from the R# forum on this topic.

Update: The feature will be in R# 5.0. See the official announcement.

The Chairman
Reading the thread is not a good advertisement for R#: The thread is from July, it is now October and the tone of the responses were pretty arrogant, though that could be cross language thing.
graham.reeds
**Question**: *Now that RGreatEx is no longer being sold, is there any plans to include similar functionality into Resharper?* **Answer R# Help Desk**: *Yes.* ... say no more...
The Chairman
+1  A: 

You could take a look at the resource refactoring tool at

http://www.codeplex.com/ResourceRefactoring

It's an instance-by-instance tool rather than a batch replacement tool. It's free and standalone so you don't need Resharper or Coderush.

Dr Herbie
I tried this tool, but it doesn't work as I need. I have most of the strings in .aspx files, which are actually hard coded attributes (see more details in my post, I updated it). Both CodeRush and ResourceRefactoring seem to ignore them, which doesn't help me. :(
Diego
A: 

VisualStudio lets you search and replace with RegEx. It won't be the "fix all in one shot" solution, but it should cut back on the amount manual work significantly.

Just a thought.

Ryan Emerle
Thanks, I'm trying now to find all the occurrences of the strings I have to change, but I always had difficulties with regular expressions. I think I'll ask another question if I'll get stuck (as it probably will happen, LOL).
Diego