Finally! It’s actually reasonably easy to create project templates in VS.NET 2005. Microsoft has made the process of creating custom project and page templates relatively easy by providing an export Wizard that lets you basically build your project as you want it and have VS create a project template from it. The Wizard sits on the File Menu under Export Template and lets you select to create a project or Item Template. Project Templates grab the current project as is and package it, while the Item Template Wizard asks you to select the files you want to include in your template. In both cases you can embed a few custom string expansion macros that give you the name of the project and file and a few other things.
The Wizard zips up your files into a ZIP along with a template configuration file that describes the template to VS.NET.
All that’s left to do is stick the Zip file into the VS.NET templates directory and voila your project templates are visible and reusable. The file needs to be copied into:
D:\Documents and Settings\ricks\My Documents\Visual Studio 2005\Templates\ItemTemplates
or ProjectTemplates. The Zip file apparently can go anywhere in this hierarchy to become visible.
I just did this for Web Connection. Web Connection is actually not a .NET application, but it uses VS.NET for editing of script page, taking advantage of the visual designer and the control editors. Even so there’s tremendous advantage there in that I can now copy all the required support files in one fell swoop from within Visual Studio (instead of Web Connection’s own Project Wizard which does the same). But the real benefit for Web Connection comes from the Page Template which allows removing some of the default XHTML gunk, default code block that isn’t used, allows adding of a Web Control reference and adding a default custom WebPage control reference into the page right from the start. This saves several steps that take a bit of explaining usually, so it’s much nicer to have this done in a single step!
One thing that I couldn’t figure though is how to add a WebControl library to the Toolbox, but I suspect that’s probably not as easy <g>… another day for that.
This is a big step forward and provides oodles of benefits for any vendor shipping source code related tools as you can now much more easily provide custom items that automatically include necessary references to projects or namespaces in classes etc.
But it’s also great for personal day to day use – I immediately went in and modified my default class and ASP.NET page definitions to match my needs because it’s so easy to do now.
And to make things even more surprising this stuff is actually – gasp - documented reasonably well (not the process, just the reference):
http://msdn2.microsoft.com/en-us/library/6db0hwky
Scott Guthrie also posted about ASP.NET project templates a few weeks back which got me started on this earlier.
Kudos for this cool feature.