Dela via


Creating Project Templates (Visual Studio Tools for Applications)

A project template includes all of the files that are necessary to begin a specific type of project. Visual Studio Tools for Applications project templates are similar to the many predefined project templates that are installed with Visual Studio, such as a Windows Forms application. For more information about Visual Studio project templates, see Visual Studio Templates.

Creating Project Templates

There are three prerequisites for creating a project template:

  • You must register your host application. Registering the application enables you to associate the project template with your host application by specifying the host identifier for the host application in the project template. For more information about registering your host application, see How to: Register the Host Application.

  • You must create a proxy for your application's object model. The proxy enables the project template to provide an entry point, known as a host item, to your application's object model. For information about creating proxies, see Creating Proxies.

  • You must add the proxy DLL to the global assembly cache. For an example of adding a proxy DLL to the global assembly cache, see Walkthrough: Creating a Project Template Using the Project Template Wizard.

Project Template Generation Tool

You can create project templates by using the Project Template Generation tool (Projectgen.exe) that Visual Studio Tools for Applications provides.

Project Template Files

A project template in Visual Studio Tools for Applications is made up of several files that are compressed into a .zip file. A project template includes the following project files:

  • A host item blueprint file for each host item (<HostItem>.Designer.xml).

  • A user code file for each host item (<HostItem>.vb or <HostItem>.cs).

  • A Visual Studio template file (.vstemplate).

  • A Visual Basic or Visual C# project file (.vbproj or .csproj).

  • AssemblyInfo.vb or AssemblyInfo.cs.

  • Any resources to be included in the project (Resources.resx).

  • The user interface for adding resources (Resources.Designer.vb or Resources.Designer.cs).

  • A file that provides access to the application's settings (Settings.Settings).

  • The user interface for modifying the application's settings (Settings.Designer.vb or Settings.Designer.cs).

The project files are compressed into a single .zip file, and the .zip file can then be placed in the location that is recognized by Visual Studio for custom project templates.

Host Item Blueprint

The host item blueprint file is an XML file that contains a declarative representation of the programmable objects in the host item. The XML serves as a blueprint for the Visual Basic or Visual C# code that is generated.

The name of the host item blueprint contains the name of the host item, followed by "Designer.xml". For example, if the host item is named ThisApplication, the host item blueprint is named ThisApplication.Designer.xml. For more information about host items, see Exposing Host Objects to Add-Ins.

When an add-in project is created, this read-only host item blueprint file is not visible in Project Explorer by default. The add-in developer must click Show All Files in Project Explorer to view this file. The developer should not manually make revisions of any kind to this file.

User Code File

The user code file is the host item class in which the add-in developer writes code to automate the host application. This code file is named by using the name of the host item with a .vb or .cs extension. For example, if the host item is named ThisApplication, the user code file is named ThisApplication.vb for add-ins created using Visual Basic and ThisApplication.cs for add-ins created using Visual C#.

Visual Studio Template File

The Visual Studio template file is an XML file with a .vstemplate extension. It contains metadata that is used by Visual Studio to define how to display the project in the development environment. The metadata includes information about the template, such as the name, description, and project type (Visual Basic or Visual C#). It also contains a listing of all of the project items in the project template. This list is used to define how to create an instance of a project from the project template, including how to copy code files, replace variables, and start wizards.

Visual Basic or Visual C# Project File

The project file is used within the development environment. This file stores information specific to your project, including configuration settings, debug/release settings, user source files, and any references. This code file has a .vbproj or .csproj extension. The project file also contains project properties that are specific to Visual Studio Tools for Applications. For more information, see the ProjectProperties section in Descriptor Schema for Projectgen.exe. You can manually edit the project file to set properties that are not specific to Visual Studio Tools for Applications, but not all properties that are available in Visual Studio 2008 project files are supported in Visual Studio Tools for Applications project files. For more information about the project file elements, see MSBuild Project File Schema Reference.

Storing Custom Properties

You can manually add an optional HostProperties section to the project file as a property bag to store name/value pair information in the project file for use by an in-process host. For more information, see Creating In-Process Hosts.

The following is an example of properties in the HostProperties section of the project file.

<HostProperties>
    <Property Name="ApplicationPath"
        Value="%SYSTEMDRIVE%\ShapeAppSamples\ShapeAppMFC"/>
    <Property Name="AddInLocation" Value="%USERPROFILE%\My 
        Documents\ShapeAppMFC\AppAddIns"/>
</HostProperties>

Project Properties

There are a number of project property-related files that must be included in the project template .zip file.

AssemblyInfo(.vb or .cs)

The AssemblyInfo.vb or AssemblyInfo.cs file provides information about the add-in, such as the name and description of the assembly.

Resources.resx

The Resources.resx file contains data that describes the resources for your project, such as bitmaps and localization strings. For more information, see Resources Page, Project Designer.

Resources.Designer(.vb or .cs)

The Resources.vb or Resources.cs file provides a user interface to create and manage resources for your project.

Settings.Settings

The Settings.Settings file contains data that describes the properties settings for your add-in. For more information, see Settings Page, Project Designer.

Settings.Designer(.vb or .cs)

The Settings.Designer.vb or Settings.Designer.cs file provides a user interface to store and retrieve property settings for your add-in.

Customizing Project Templates

You can customize project templates that you create using Projectgen.exe the same way that you customize other Visual Studio project templates. For more information, see Customizing Project and Item Templates.

Including Item Templates with Your Project Template

You can include standard Visual Studio item templates in the Add New Item dialog box. You can also create custom item templates for your Visual Studio Tools for Applications project.

The following Visual Studio item templates are not supported in a Visual Studio Tools for Applications project.

Item Template

Language

Bitmap

C#

Class Diagram

C#

Cursor File

C#

Icon File

C#

Local Database

All

Local Database Cache

C#

Style Sheet

C#

For information about how to create custom item templates, see How to: Create Item Templates.

For information about how to include custom and standard item templates for your Visual Studio Tools for Applications project, see Host Configuration Registry Key Settings.

See Also

Tasks

Walkthrough: Creating a Project Template Using the Project Template Wizard

How to: Create a Project Template Using the Projectgen.exe Command-Line Tool

Concepts

Creating Project Templates Using the Project Template Generation Tool (Projectgen.exe)

Reference

Descriptor Schema for Projectgen.exe