Please let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
to share? Submit it here!
You can extend Visual Studio .NET by adding custom project templates. This tip, excerpted from InformIT, demonstrates how to copy a project template from the existing set of templates that comes with Visual Studio.NET. The entire article on InformIT has more information, such as custom attributes and class libraries.
A class library is simply a DLL, and custom attributes are classes that inherit from System.Attribute, allowing you to define additional metadata to incorporate into your .NET assemblies. (Metadata is information added to .NET assemblies to help mitigate "DLL Hell.").
Select File, New, Project to open the New Project dialog box, which displays a list of project types from which you can select. (You get the greatest selection of new kinds of projects with Visual Studio .NET Enterprise Architect.) These project templates contain elements that are fundamental for the selected type of application. For example, if you select the Console Application template, you get a project that contains a class with a static main method. This static main method is the entry point for a console application.
And here's the advantage of using project templates: You might normally have to work to discover that a console application has a static main method that uses the Single-Threaded Apartment threading model (STAThread) attribute, but the Console Application project template takes care of this detail for you.
The easiest way to create a project template is to copy an existing project template. Existing project templates are defined in folders in C:Program FilesMicrosoft Visual Studio .NETVC#VC#Wizards, if you use the default installation folder for Visual Studio .NET. The CSharpDLLWiz folder contains a project template close to the one that we want to create for this example, so we'll copy this project template.
To copy the project template, follow these steps:
- In Windows Explorer, copy the C:Program FilesMicrosoft Visual Studio .NETVC#VC#WizardsCSharpDLLWiz folder.
- Paste the folder in C:Program FilesMicrosoft Visual Studio .NETVC#VC#Wizards. This step will create a folder named Copy of CSharpDLLWiz.
- Assign a new name to the copied project template folder. For this example, I used the name CSharpAttrWiz. (You can use any name you want.)
The new folder contains Scripts and Templates subfolders. These subfolders contain files that support the wizard behavior, including template files that are used to generate the source code files in each new project created from the template.
To read the entire article from which this tip is excerpted, click over to InformIT. You'll have to register to read it, but hey, the registration is free.