Resharper templates for Block and PageData

I always feel wrong when I need to do the most basic thing in Episerver development – adding a new page type. First options was to use „Add New Item…” dialog and make use of EPiServer CMS Visual Studio Extension.

add new episerver item

After that step I have to delete almost everything cause I stick to simplicity.

Second way is to copy-paste existing page. After that you have to rename, remove unwanted code and update Guid. Updating Guid is tricky cause you can forget and waste some time discovering it after rebuilding and running application.

R# file templates

What I do now, is using Resharper feature File Templates.

You go to Resharper->Templates Explorer, the click on File Templates:
resharper file templates

I created three: Block, PageData and ‚PageData more’ (all have auto generated new Guid). You can import my examples downloaded from here. Drag importet templates on top of the quicklist I also suggest delete all the templates under evil classic „ASP.NET (C#)”, and remove „Razor MVC Partial View” from quicklist (so PageData would be accessible from letter „P”).

Having this done, when you click Alt+Insert in Solution Explorer you will get simpler context menu with Block – „B” and PageData – „P”.

Resharper context menu add block

Your own template

Your can double click existing template or click “Create new”.

resharper create or edit file templates

The variables have to be set in the right pane. I just set them to the defaults like for “Class” template. The most important variable is $CLASS$, which will appear couple time in more sofisticated cases, the rest is mostly static.

resharper edit file template

I encourage you to change my defaults, probably all your Blocks should derive from SiteBlockData and the same for Pages (at least I do that in my projects). Maybe you have some favourite properties, you want always to have by default.


My colleague Bartek is testing a lot so every factory need interface and contracts for interface methods. I added „Interface with contract” (Code Contracts).

Happy shortcuts using!