Diego
Diego

Reputation: 7562

Visual Studio - Tool to replace hard coded strings with resources

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...

Upvotes: 6

Views: 14217

Answers (7)

negyxo
negyxo

Reputation: 252

I've just published new tool called Jinnee.Package for string refactor. You can find it on Visual Studio gallery: http://visualstudiogallery.msdn.microsoft.com/7ec5a225-dea4-47ae-8ebc-450d2980937f?SRC=Home

Upvotes: 1

j_maly
j_maly

Reputation: 1121

Check out the new open source project VisualLocalizer on CodePlex: VisualLocalizer page. If you have some ideas, post them as issues - the project is under development and we welcome feedback.

Upvotes: 3

The Chairman
The Chairman

Reputation: 7187

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.

Upvotes: 1

Ryan Emerle
Ryan Emerle

Reputation: 15811

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.

Upvotes: 2

Dr Herbie
Dr Herbie

Reputation: 3940

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.

Upvotes: 3

Anton Gogolev
Anton Gogolev

Reputation: 115751

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.

Upvotes: 1

Daniel Elliott
Daniel Elliott

Reputation: 22857

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

Upvotes: 1

Related Questions