To get started, check out a wizard generated .vstemplate file. If you have been following along and you have generated the template on your own system, double-clicking the file should open it in Visual Studio or IE. You'll see that this, like so many of the data files in .NET, is an XML file. Here's the top level:
<VSTemplate Version="2.0.0"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"
Type="Project">
<TemplateData>
< ... >
</TemplateData>
<TemplateContent>
< ... >
</TemplateContent>
</VSTemplate>
The TemplateData element contains sub-elements like Name, Description and ProjectType. The TemplateContent element contains sub-elements for the actual files, like the .vbproj file, that will be the basis of your new project. In the wizard generated template, you will notice that the "target" files are named the same as the actual files like this:
<ProjectItem ... TargetFileName="Form1.vb">Form1.vb</ProjectItem>
This gives you the flexibility of using files with other names in your template. For example, your project might have a naming convention so that a Form is named ProjXYZFm123. You can include that in a template for a new project without renaming anything.
More flexibility is available with the ability to actually change the content of the VB code itself using parameters in the .vstemplate files. For example, you can embed a statement like this in your VB code before generating the template.
MsgBox("Project name passed as parameter: " _
& "$safeprojectname$")
When a new project is created using that template, the code in the project will look like this:
MsgBox("Project name passed as parameter: " _
& "ParmTest1")
Note that when the wizard processes $safeprojectname$, the name with a "1" appended that you're used to seeing as project names in Visual Studio is generated. It will remove blanks and any other illegal characters too.
The illustration below shows parameters in action.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
When you used the Export Template wizard to create a project template, you probably noticed that another options was available to create an item template. These are simply the items that you can select from when you select Add New Item... under the project menu. The process of creating item templates are about the same as the process for project templates except that you also have to select the parts of the project that will be in the item and any references that your item depends on.
Microsoft also includes something they call Starter Kits into this category of tools. But as they candidly state:
"Visual Studio templates and Starter Kits are built and used in almost exactly the same way. A distinction is made between Starter Kits and a templates to provide a level of expectation to someone downloading and using them."
But then they say, "Several key features are required to separate a Starter Kit from a template."
I added the bolding on the word "required". How are these "key features" required? The answer is, they're not. It's just a marketing thing. Don't worry about it.
This article will get you started making your own templates. The key information that is missing is the exact definitions of the XML elements that are used in the .vstemplate file. Unlike some books which fill chapters with detailed (and sometimes out of date) information that you can get online, I recommend that you get what you need online at MSDN. Use the search key "Visual Studio Template Schema" and the hints in part II of the Visual Basic .NET 2005 Express tutorial.
article illustrations © Dan Mabbutt

