While application development provides plenty of opportunities to be creative, there are numerous aspects of every project that require developers to perform the same tasks over and over again. Automating such tasks provides you with more time to concentrate on the more challenging aspects of your work. Visual Studio 2005 provides numerous ways to boost productivity; templates are just one example. This article describes creating and using project templates.

Templates

Visual Studio 2005 has two different kinds of templates. The first is a standard template. Standard templates are included with a Visual Studio 2005 installation. You can find these templates in the Visual Studio 2005 directory under the Program Files directory (assuming the default directory is used during installation). On my system, the following directory points to the standard templates:

C:\Program Files\Microsoft Visual Studio\8Common7IDEProjectTemplates

The second type of template is user or custom templates. A registry key (HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0) specifies where custom project templates are stored on a development machine. The default directory for these templates is contained in the templates subdirectory of the project's directory of the Visual Studio 2005 installation. The default directory is:

C:\Documents and Settings\<username>\My Documents\Visual Studio 2005\Templates

To control where project templates are stored via Visual Studio 2005, you simply select Tools | Options from the drop-down menu to open the Options window. In this window, expand Project and Solutions and select General. It includes a field for designating where project templates are stored.

Template file structure

Templates are contained in compressed files. A good example is the directory for standard Windows C# applications:

C:\Program\FilesMicrosoft\Visual Studio\8Common7IDEProjectTemplatesCSharpWindows1033

By default, the following template files are included in this directory:

|> ClassLibrary.zip: Project template for a Class Library project.
|> ConsoleApplication.zip: Project template for a Windows console application project.
|> CRCSharp.zip: Project template for a Crystal Reports Application project.
|> EmptyProject: An empty project.
|> WebControlLibrary.zip: Project template for a Web Control Library project.
|> WindowsApplication.zip: Project template for a Windows Application project.
|> WindowsControlLibrary.zip: Project template for a Windows Control Library project.
|> WindowsService.zip: Project template for a WindowsService.zip.

The compressed files are standard, so you can easily view the files' contents with a project like WinZip or via Windows XP compressed folder.

The zip files contain all files necessary for creating a project. In addition, it contains an extra file with the extension vstemplate. This template file contains all information necessary to create a project and add appropriate files to the project.

The vstemplate file stores project template metadata as XML. In addition, it includes the details of how the template is displayed and what is included with it. As an example of a standard project template, the WindowsApplication.zip file contains the following files: assemblyinfo.cs, consoleapplication.csproj, csconsoleapplication.vstemplate, and program.cs.

Creating your own template

The simplest way to create your own template is by using another template as the starting point; that is, create a new Visual Studio 2005 project by selecting a template. Once the project has been created, you can make your changes like adding forms, classes, and so forth. Finally, save the project.

Once the project has been saved, you can select Export Template from the File drop-down menu within Visual Studio 2005. This opens the Export Template Wizard window, which guides you through the creation of the project template.

First, you select the template type (which is project template in this example). A drop-down list is available to specify the project to be used as the base for creating the template (it defaults to the currently open project that you just saved). Another drop-down selection is present for choosing the language (your choices depend upon what is installed) that the template will use.

At this point, you select the next button and a final window appears. This window allows you to specify an icon for the project template (it appears in the Create A New Project window) along with assigning a template name. Also, a field is provided to type a description of the template. The output location of the new project template file (compressed file) is displayed, but it may not be edited.

Finding templates online

In addition to the previously described standard templates that are included with Visual Studio 2005, there are starter kits available from Microsoft as well. The starter kit concept promotes the consumption of sample code applications and projects through community sites. These samples may be downloaded from the community Web sites.

You may search online for templates or starter kits when creating a new project. The New Project dialog box provides an option called Search Online Templates. This option allows you to search for starter kits online by keyword. If a match is found, you can choose to download and install it into the appropriate directory so it may be used as a template. These starter kits provide an opportunity to learn via code that has been tested and developed by professionals. The MSDN and MyCodezone sites are examples of online template resources.

Conserve time and energy

The main selling point of Visual Studio 2005 templates is the ability to automate redundant steps, thus saving developers time. Many organisations include a base set of features in new Visual Studio 2005 projects, including standard graphics, splash page, login form, specific references and so forth. By including these elements in a project template, you can easily create new projects with the template and avoid having to manually do it each time.

Do you use templates or other tools to boost your productivity? Share your experiences with the .NET community by posting to the article discussion.

Cast your .NET This was published in Cast your .NET, check every Thursday for more stories

Related links

Comments

1

Zack Stauber - 21/06/08

Actually WindowsService.zip is not included with Visual Studio .NET 2005 Standard Edition, and is not available for download on MSDN as far as I can find. It is however included in SharpDevelop 2.2, so if you are a C# user, that is your only option.

» Report offensive content

2

Himanshu kumar - 26/07/08

Kool man....

You explain it very well

» Report offensive content

3

Eddie Hadley - 30/10/08

Tony,

Useful article.

I'm here because my C# templates have disappeared from my VS 2005.

And thanks to your article, I've located those zips - eventually (:-).

You have a little reviewing to do though, e.g. with those Path names:

C:\Program Files\Microsoft Visual Studio\ \8Common7IDEProjectTemplates

should be
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\

And again:
As an example of a standard project template, the WindowsApplication.zip file contains the following files: assemblyinfo.cs, consoleapplication.csproj, csconsoleapplication.vstemplate, and program.cs.


Those console app files are to be found in ConsoleApplication.zip, not WindowsApplication.zip. (:-(

A bit of time lost there . . . but my congratulations for the initiative.


Best regards,

Eddie

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

3

Eddie Hadley - 30/10/08

Tony, Useful article. I'm here because my C# templates have disappeared from my VS 2005. And thanks to your article, I've located ... more

2

Himanshu kumar - 26/07/08

Kool man.... You explain it very well ... more

1

Zack Stauber - 21/06/08

Actually WindowsService.zip is not included with Visual Studio .NET 2005 Standard Edition, and is not available for download on MSDN as ... more

Log in


Sign up | Forgot your password?

  • Staff Aussies to pay more for Win 7

    If you are looking to make some money in these troubled times, perhaps importing copies of Windows 7 could be for you. Read more »

    -- posted by Staff

  • Staff Firefox: Greens want it, 3.5rc2 not up to par

    This week's roundup looks at the situation surrounding a campaign to change Outlook HTML renderer, a Greens MP wants to install Firefox but is restricted and all the photos from the iPhone 3GS launch. Read more »

    -- posted by Staff

  • Chris Duckett Microsoft misses the Outlook point

    Ask designers which mail program is the bane of their existence, and you'll find that Outlook tops the list. The reason why the most popular email reader is also the most painful is simple: it uses Word to render HTML emails. Read more »

    -- posted by Chris Duckett

What's on?