{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Using Templates – A Cousin of Starter Kits
Summary
Visual Studio 2005 and 2008 include a great feature to make templates out of whole projects or individual items. These templates can be freely used by anybody to quickly create baseline projects or items in Visual Studio with lot of functionality.
 
Table of Contents

Why a template?

Creating a Project Template

Figure 1. A project template

Figure 2. Template Options

The Template .zip file

Creating a New Project out of the template

Figure 3. My Company Web Service template in New Project dialog box

 

Why a template?

Starter Kits and Templates are new features in Visual Studio (2005 and 2008) and they can be immensely useful. Every code example that you give to your customer can now be a starter kit or a project template.

Say, you have created a Web Services API to access some sophisticated functionality on your web site. Typically, you would create an example solution in C# or VB.Net and zip up the files from the solution/project and give them to your customer.

Then the user will open up that project and then learn from it (for example, how to access your web services) or copy-paste pieces of that code into his or her project, etc. This could get a bit cumbersome.

With the template feature in Visual Studio, the work you have to put into creating these templates is not that much more but the end user will be able to create a new project with that content with just a single click. Alternately, if you create item templates, the user will be able add that content into the existing projects.

Creating a Project Template

To create a new starter kit or a new project template or a new item template (i.e. a single aspx page or class file), use File – Export Template menuitem and follow the Export Template wizard.

Figure 1. A project template

Figure 1. A project template

In this case, I am exporting a project called FirstWebService. The original project itself was created with the ASP.NET Web Service template. That, of course, is not a problem. Let’s say you have a set of required files, references, configuration settings, etc. to create a web service using the web service API of your company.

You would include all those files and settings in the above project and prepare a template out of it. The customers using your web services will be able get started right away with using your web services, instead of going through a ton of documentation about what to include, etc.

Figure 2. Template Options

Figure 2. Template Options

The template options of Export Template Wizard are shown above. As you can see, this template will be saved as a .zip file. I named this template ‘My Company Web Service’.

The Template .zip file

After you click the Finish button, you can see the .zip file saved in the following location: C:\Users\Administrator\Documents\Visual Studio 2008\My Exported Templates. This is the output location specified in the Export Template Wizard.

If you open that zip file, you will see all the source files from your project – no binaries will be included, of course. In addition you will see two other files:

__TemplateIcon.ico

MyTemplate.vstemplate

The .ico file is the icon that shows up next to the template (My Company Web Service) in the New Project dialog box.

And MyTemplate.vstemplate includes all the relevant information to make up a project like the one you had while creating this template. This .vstemplate contains the information like the following:

  • Name of template – here it’s ‘My Company Web Service’
  • Description of the template – for example: ‘Web Service using my company API.’
  • Project Type – here it’s CSharp
  • The template icon
  • Project file (.csproj) and the relevant files (.asmx, .asmx.cs, .cs, .config, etc.)

Creating a New Project out of the template

As you can see in Figure 3, the template for the C# project we saved will show up under Visual C# in the New Project dialog box. As we named it, the template shown here is ‘My Company Web Service’.

Figure 3. My Company Web Service template in New Project dialog box

Figure 3. My Company Web Service template in New Project dialog box

The entire project you built is available to somebody for extending with just a click of a button; as mentioned before, this is ideal for developing samples, base projects, etc.

Take a Quick Quiz on this Article

1. How do you create template out of a Visual Studio project?



: You would be saving it as a template.
Question 1 of 5
Bookmark and Share This

More Articles With Similar Tags
This test has a few questions on creating templates with Visual Studio.
icon-starter-kit-installer.jpg
Visual Studio comes with a lot of features that provide the UI and code development capabilities. This article explores a feature that lets you get started with a site even faster.
How do you develop starter kits with Visual Studio?
Top Tags in Related Articles
starter kits templates web sites quickly
About  Contact  Privacy Policy  Site Map