Jakew
Consulting, hacking, and motorcycles

VS Templates – getting hands on

Thursday, 27 December 2007 17:42 by jakew

So early today I dug in to the T4 template engine. Now I’m digging in to Visual Studio’s templates. These are a whole lot easier to deal with – or at least I found the docs quicker.

Making a VS template is very easy. Just open a project and go to File and click Export template. By this point that should be well known and old hat. But that is just the beginning. VS templates allow you to extend them by adding a wizard.

To add a wizard first create an class library with a class that implements the IWizard interface. Stub out all of the methods expect RunStarted. You can use the other methods, but RunStarted is the first thing VS runs when it finds a wizard in a template.

You can do pretty much anything you want inside your wizard. In this case I add a single replacement value to the replacementDictionary ($message$). You could do other things though. For instance – the automationObject is actually a EnvDTE object so you can reach in to VisualStudio and take control of the whole environment.

My plan is to combine VS Templates and the T4 engine so I can do some big automation for myself. The biggest challenge I can see right now is that the output from the T4 engine has to go in to a value in the replacementDictionary.

Again – the trashcode project is here for your viewing pleasure. You’ll have to change the public key token in the template file to make it work.

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed