Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 12: Customizing the Development Environment 347
Prompt (2010) and select Run As Administrator. This will take a few minutes to run, but
afterward you’ll see the project appear in the VS New Project window. This command
imports all of the project templates from the global project templates folder into VS:
devenv /installvstemplates
If later you decide you don’t want a given template to appear in the VS New Project
window, remove the project template from the global project templates folder(s) and run
the preceding command again.
Now you’re able to create and use custom project templates. While you might create
projects occasionally, it’s a common task to create project items, covered next.
Creating New Item Templates
Sometimes, you use certain item templates frequently but often modify the contents of
the item for your own purposes. In these cases, it’s useful to be able to create a custom
item template instead. The example in this section will be to create something that isn’t
currently an item in VS: a new item template for enums. To create a new item template,
we’ll create the file for holding the item, save the new item, and then use the new item in
a project.
Creating an Item Template
The easiest way to get started with creating a new item template is to start a new project
that has an existing item template that is most similar to the one you want to create. For
a new enum template, all we need is a class file, so any project that allows you to add a
class file template will work. The example in this section will use a Console project, but
the project type doesn’t matter because we’ll only be interested in extracting one file for
the item template. The following steps show you how:
1. Press CTRL-SHIFT-N to create a new project and select Console Application. Name
the project anything you want and set the location for anywhere you like; name and
location don’t matter because we are only interested in the item template file and not
the project. Click OK to create the project. VS will create a new solution with a project.
By now, you’ve seen plenty of new Console applications in previous chapters, and this
will be the same.
2. Right-click the project in Solution Explorer, select Add | New Item, select Code File,
name the file Enum.cs (Enum.vb for VB), and click Add. This will add a new blank
file to your project.