DevCity.NET -
Customizing VS2008 default project templates
Kevin Gallagher
Developer work at Oregon Department of Revenue 
by Kevin Gallagher
Published on 6/10/2009
This tutorial will guide you through the basic steps needed to alter the VB.NET Windows forms application project template in VS2008. Once you feel comfortable with this simple modification you can do the same for other project templates.



There are a multitude of reasons for altering a template.  For instance you probably do not write new applications much but instead work on one project for a long time then move to a new project. Usually developers writing a new Windows forms application have several mundane tasks to perform, ranging from adding staple code modules, global exception handlers, menus etc. By selecting the default Windows forms application template none of the above is there, so we must manually complete these tasks.

Sure you can simply create a project and export it as a template also which is another option.

A better solution is to have the default windows form template to have staple modules, global exception handlers, menus etc. done when selecting a new project.

Modifications to a template (see attached project for a good example)

  1. Find code modules you want to include into the modified template.
  2. Close VS2008.
  3. Open the folder C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\VisualBasic\Windows\1033
  4. Create a complete backup of the folder which can be done by renaming it to say
  5. Create a new folder called
  6. Copy contents from into
  7. Copy files from step one into
  8. Open windowsapplication.vbproj with notepad.  Find the line <COMPILE Include="Form1.vb">
  9. Directly above you will see <ITEMGROUP>
  10. Between these two lines insert the modules using the example below. So you have a module named ConvertMethods.vb we add the following which includes a folder destination for the module. The folder will be created when using this template and the module will be placed into the folder.
  11. The folder name is your choice. Repeat this step for all modules, classes and other files you are including. <COMPILE Include="Extensions\ConvertMethods.vb" />
  12. To add References simply locate the item group directly above step 9 and 10, grab the reference from another project by editing the project file in VS2008 and use it here.
  13. Save and close windowsapplication.vbproj.
  14. Now locate windowsapplication.vstemplate and open it in Notepad.
  15. Find the line containing TargetFileName="My Project\AssemblyInfo.vb", select the entire line and copy it above.
  16. In the copied line (using ConvertMethods.vb as in step 11)  change TargetFileName="My Project\AssemblyInfo.vb" to TargetFileName="Extensions\ConvertMethods.vb" .
  17. Repeat step 16 for each added module, followed by saving the file.
  18. Fire up VS2008 and create a new Windows forms application. If you followed the steps above your additions will be in the project. If not, research what went wrong and correct it or simply close VS2008 and delete the folder and rename
  19. to Restart VS2008 and you are back to the original template.

See attached WinZip file for a basic template and also a demo project showing additions to the default template in action. I kept the demo project simple for ease of learning. I mentioned in related articles "Extension methods" simply because the basic template and demo project have extension method within that you can use in your daily coding outside of the content here.