Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Creating Custom Item Templates in Visual Studio 2005

In my last post, I talked about How To Customize Existing Visual Studio 2005 Templates for Coding Productivity.  I essentially modified the existing C# Class.cs template that ships with Visual Studio 2005 to make it more useful in my development environment.  This provides me a bit of code generation functionality out-of-the-box, allowing me to spend less time typing mundane code and more time solving problems.


Rather than tinkering with the existing templates that ship with VS 2005, however, Visual Studio 2005 allows you to create custom templates based on existing classes and projects in the IDE.  You can create these templates using the Export Template Wizard located on the File Menu.


 


The VerboseCSharpClass Custom Template


I tend to add a number of regions, XML comments, and various overrides in all my C# Classes.  Unfortunately, the default C# Class Template that ships with Visual Studio 2005 is pretty bare, requiring me to create the same class features over and over.  And even though I tend to add these same features a lot, I am still not consistent in how I name the regions, write the XML comments, etc.All this typing distracts me from the real work and consumes precious minutes throughout the day.


My custom VerboseCSharpClass Template is to solve my problems.  Now when I need a heavy duty class that requires such features, I just choose it from “Add New Item” as opposed to the generic C# Class Template that ships with VS 2005.


 



 


Creating The Template


Creating the template is nothing more than creating a C# Class with all the statements, fields, properties, methods, etc. that you want included by default when you create the class.  Instead of hardcoding a class name and root namespace, however, you will instead put a couple of parameters used by Visual Studio 2005 to generate them for you within the context of the Add Item Process.  Here is my quickly created class for testing purposes:


 



 


Exporting the Template


Exporting the template and adding it to Visual Studio 2005 is about as easy as you can get.  Once you are happy with the template, save it and choose File > Export Template… on the menu.  The export wizard will walk you through a 4-step process that saves the template as a *.Zip file and automatically imports it into Visual Studio 2005 for you.  Here is a collage of images showing the process:


 



 


Conclusion


Whether you want to modify the existing default templates that ship with Visual Studio 2005, or even better, create new ones by using the Export Template Wizard, it would be a crime not to take advantage of these code generation features to help you be more productive in your day-to-day development efforts.  These two features are in addition to the more obvious new way to improve your productivity – Code Snippets.


 


Recent Posts



 


DrinkingJapanese Sencha Green Tea


 

This entry was posted in Visual Studio 2005. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

2 Responses to Creating Custom Item Templates in Visual Studio 2005

  1. Callum says:

    Ahhh…the option was missing because of my IDE settings. When I first opened the IDE I must selected a mode that hides that option.

  2. Callum says:

    Useful, but I cannot for the life of me get the “Export Template…” option to appear in the Fie menu. I have Team Suite Edition! What gives?

    Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>