Announcing: Smart Resource VS2013 extension

A (long) while ago I blogged about a Macro to make it a lot easier to work with (SharePoint) resource labels.

Since then macros have died along with Visual Studio 2010 L

During a “fun coding Saturday” at Delegate I updated and converted it to a Visual Studio Extension – available through the Visual Studio Gallery, right here 🙂

What it Does

1. You highlight a string in VS

2. Hit the shortcut (default Alt+r, Alt+r)
3. Write a name for the resource key to create(optionally use an existing if one exists with same value)

4. And you’re done.

It will then add the resource key to your existing resx file, it will type in “$Resources:….” as needed. If it’s an aspx/ascx file it will also throw in some “<%=” and “%>” tags.

Why?

It will save me 1 minutes every time I need to do a SharePoint resource AND it will make it almost a no-brainer to always use resources instead of a hassle.

However there is no reason to limit this to SharePoint development; it can be used throughout.

Other tools like Resharper and Coderush have their own way of doing it, but they really didn’t work well with the SharePoint way of handling resources.

How to Install

Go to Visual Studio 2013, Extensions and Updates and search for “Delegate” or “Smart Resource”.

Hit install.

Sorry about missing support for Visual Studio 2012, some of the references for the options dialogs have changed and I didn’t want to maintain two code branches.

Details

A few details worth noting are that:

  • It will look for a resx file named the same as your project first, if not found then “Resources.resx”, then “*.resx”. If you have more than one candidate it will error out.
  • It will detect the file type and use an appropriate replace pattern for that one. You can change what is inserted in the Options:

Substitute with your own resource lookup method.

  • For some VS wizards, e.g. the SharePoint Feature designer there is no API to get and replace the text selected so it will revert back to the clipboard. You copy the text first, hit Alt+r,Alt+r, select key and then paste the result back into your design interface

Room for Improvements

There are possibly many areas of improvement, for now it is a time saver for me.

What may be lacking is:

  • No limits to language patterns (I could make a list…)
  • Handling of usings/references at the top of the file (I just let ReSharper add whatever using I need)
  • A better way to handle wizards (remote control the clipboard?)
Advertisements

About Søren Nielsen
Long time SharePoint Consultant.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: