| You are here: | About>Computing & Technology>Visual Basic |
![]() | Visual Basic |
Templates for New Projects and New ItemsJul 27 2007 Another way to increase productivity with Visual Basic .NETWhat's a Template? When you start a new project in VB.NET, you have to select the type of project such as Windows Application or Class Library. These are templates. In addition, when you add a new item to your project (from the Project menu, select Add New Item) you select from item templates. But wouldn't it be nice if you could use a template that already has a few of your own tweaks in it? If there are local standards, special requirements, or just programming styles that you like to use, you can start out with part of your work already done by creating a custom template. (This works in both Visual Studio 2005 and VB.NET Express!) Before we go any further, let me make it clear that this is not the same thing as something Microsoft is trying to sell called "Enterprise Templates". That is a high level architecture concept that Microsoft claims will allow you to organize and control "distributed applications with multiple projects." About Visual Basic is focused on down-to-earth programming. In addition, none of this was available in Visual Studio 2003. Templates actually were available (after all, New Project still worked the same way), but were undocumented and Export Template didn't exist. So you could do it only if you were willing to blaze your own way in an uncharted software wilderness. But in 2005, the basic operation to create your own template became about as simple as it could be!
The screen below shows how the process looks. -------- If the screens look funny to you, I used Windows Vista for this example. Visual Studio 2005 (but curiously, not VB.NET 2005 Express) requires a special update before it will run on Windows Vista and the file locations can be significantly different. Here's where the template, testtest can be found in Windows XP after being generated by VB.NET 2005 Express: -------- This is important because, for some reason, a lot of the books out there don't seem to even be aware of the existance of the Export Template wizard. (John Paul Mueller's Mastering Web Development book, for example.) Doing it this way can get mighty complicated fast, especially since even the instructions at MSDN don't seem to track what you will see on your own computer much of the time. So if at all possible, I'd stick with the wizard. My experience is that the VB.NET development software - VB.NET Express and Visual Studio 2005 - are updated better than the documentation and you're less likely to run into problems that way. For example, MSDN states that if you manually create templates instead of using the wizard, you should place them in: My Documents\Visual Studio 2005\Templates\ProjectTemplates The My Documents folder has a new name in Vista. (See the first illustration above.) And Mueller's book tells you to put them in a subdirectory of the Program Files > Visual Studio 8 > ProjectTemplatesCache directory. (It's a long path ... I left a lot out.) A coder could get confused! However ... The heart of the process of creating a template manually boils down to three basic steps. (After you design what you want your template to do. This is just the process of actually creating it.)
Generating a template using the wizard is easy, but there are a few more options available too. The next page tells you about them. article illustrations © Dan Mabbutt |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


