OdeToCode IC Logo

Use a ReSharper Template for Script Files

Wednesday, August 10, 2011

ReSharper Templates ExplorerUsing Alt+Ins in the Solution Explorer window is one of those ReSharper shortcuts that probably saves me hours over the course of a year (Alt+Ins is the "Create File From Template" command). There is no template out of the box for JavaScript files, but it is easy to add one (or more).

1. Go to ReSharper menu in Visual Studio and select "Live Templates...".

2. In the Templates Explorer dialog, go to the File Templates tab.

3. Right click the User Templates node and select New Template.

4. In the template that opens, the Description field holds the text that will appear in the popup menu for templates. A description like “JavaScript File” would work well.

5. Fill out the default filename field. A name like script.js will work, because you'll be able to change the name when executing the template.

5. Click the available “in everywhere” link below the description. Uncheck “Everywhere” and select “ASP.NET” (so the template is only available for web projects).

6. Add any boilerplate code you'll want in every JavaScript file into the editor window. For example, if you do a lot of work with jQuery, then you might want to go ahead and add the Intellisense references into the template.

/// <reference path="jquery-1.5.1.js" />
/// <reference path="jquery-ui-1.8.11.js" />

7. Finally, to get the template to appear in the Alt+Ins menu, you need to drag and drop the template into one or more of the project areas on the right. In the screen shot above, the template is in the ASP.NET (C#) section.

Taking a few minutes here and there to customize your environment pays a nice return on the investment.