Share via


Walkthrough: Creating a Project Template Using the Project Template Wizard

This walkthrough provides step-by-step instructions for creating a project template by using the Project Template Generation (Projectgen.exe) wizard. It requires a proxy assembly that is generated from the ShapeAppCSharp sample application. You can generate a proxy assembly by completing the steps that are shown in Walkthrough: Creating a Proxy Assembly.

For more information about the ShapeApp sample applications, see ShapeApp Samples (Visual Studio Tools for Applications).

You can use this walkthrough as a stand-alone walkthrough, or you can use it as part of the series of walkthroughs described in Walkthrough: Integrating Visual Studio Tools for Applications with ShapeApp.

This walkthrough illustrates the following tasks:

Prerequisites

You need the following components to complete this walkthrough:

  • Visual Studio 2008.

  • Microsoft Visual Studio Tools for Applications 2.0.

  • A completed proxy file (ShapeAppCSharpProxy.dll), which you can generate by following Walkthrough: Creating a Proxy Assembly.

Registering the Host Application

Before you can use the Projectgen.exe wizard to create project templates, you must register the host application.

Note

This section shows you how to manually register ShapeAppCSharp. For an example of how to use a script to register the application, see How to: Build and Run the ShapeAppBasicCSharp Sample.

To register ShapeAppCSharp

  1. Create a subfolder named Templates in drive:\ShapeAppSamples\ShapeAppCSharp. This is where Projectgen.exe will store the generated project templates.

  2. Open the Visual Studio 2008 Command Prompt window. If you are using Windows Vista as your operating system, start the Visual Studio 2008 Command Prompt window by using the Run as Administrator option.

  3. Type regedit, and then press ENTER.

  4. In the Registry Editor, expand HKEY_LOCAL_MACHINE, and then expand SOFTWARE. Add a new key using one of the following procedures, depending on what type of operating system you are using:

    • For 32-bit operating systems, expand the Microsoft node, right-click VSTAHostConfig, point to New, and then click Key.

    • For 64-bit operating systems, expand Wow6432Node, expand Microsoft, right-click VSTAHostConfig, point to New, and then click Key.

    A node is created beneath the VSTAHostConfig node.

  5. Rename this key to ShapeAppCSharp.

  6. Right-click the ShapeAppCSharp key, point to New, and then click Key.

    A node is created beneath the ShapeAppCSharp node.

  7. Rename this key to 2.0.

  8. Right-click the new key (2.0), point to New, and then click String Value.

  9. Change the name to AppName.

  10. Double-click AppName, type ShapeAppCSharp in the Value data box, and then click OK.

  11. Right-click the 2.0 key, point to New, and then click String Value.

  12. Change the name to ProjectTemplatesLocation.

  13. Double-click ProjectTemplatesLocation and type the path to the Templates directory in the Value data box. For example, if your system drive is C, type C:\ShapeAppSamples\ShapeAppCSharp\Templates.

  14. Right-click the 2.0 key, point to New, and then click String Value.

  15. Change the name to VSTAVersion.

  16. Double-click VSTAVersion and type 9.0 in the Value data box.

  17. In the Visual Studio 2008 Command Prompt window, change to the following directory: %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\.

  18. Type the following command and then press ENTER:

    vsta /hostid ShapeAppCSharp /setup
    

Adding the Proxy Assembly to the Global Assembly Cache

If you want to test the project templates that you create on the development computer, you must first add the proxy assembly to the global assembly cache. This step is also necessary when you deploy the project templates. For more information, see Securing and Deploying Add-Ins.

Use the Global Assembly Cache tool (Gacutil.exe) to add the proxy assembly to the global assembly cache.

To add ShapAppCSharpProxy.dll to the global assembly cache

  1. Open the Visual Studio 2008 Command Prompt window. If you are using Windows Vista as your operating system, start the Visual Studio 2008 Command Prompt window by using the Run as Administrator option.

  2. Type the following command, and then press ENTER:

    gacutil /i %SYSTEMDRIVE%\ShapeAppSamples\ShapeAppCSharp\ShapeAppCSharpProxy\bin\Debug\ShapeAppCSharpProxy.dll
    

    The proxy assembly is added to the global assembly cache.

  3. Verify that the ShapeAppCSharpProxy.dll file resides in the global assembly cache by locating it in %SYSTEMROOT%\Assembly\GAC.

Creating the Project Template

After you have registered the host application, you can run the Projectgen.exe wizard to create the project template.

To run the Projectgen.exe wizard

  1. In the Visual Studio 2008 Command Prompt window, change directories to the installation folder of the Visual Studio Tools for Applications 2.0 SDK.

    %ProgramFiles%\Visual Studio Tools for Applications 2.0 SDK\build number\Visual Studio Tools For Applications\Tools\ProjectGen
    

    Note

    This path assumes that you installed the Visual Studio Microsoft Visual Studio Tools for Applications 2.0 SDK to the default directory.

  2. Type the following at the command prompt and press ENTER:

    Projectgen.exe
    

There are four pages in the Project Template Wizard. The following sections describe the fields for each of the pages in the wizard.

The first page is the Specify Template Properties page, where you set properties such as name, description, and icon to associate with the template. You can use an existing project template descriptor, or have the wizard create one for you.

To specify template properties

  1. In the Template name box, type ShapeAppCSharp Add-in. This is the name of the add-in that will appear in the Templates pane of the New Project dialog box.

  2. In the Template description box, type A project for creating add-ins for ShapeAppCSharp. This description appears above the Name box in the New Project dialog box whenever an add-in developer selects the associated template.

  3. In the Default project name box, type ShapeAppCSharpAddIn. This specifies the default project name that appears in the New Project dialog box. An incremental number is appended to this name for each project that is created.

  4. Leave the Template icon box blank. Typically, you would click the ellipsis (…) button and navigate to the location where your icon is stored. This is the icon that appears in the Templates pane of the New Project dialog box. For this walkthrough, use the default icon.

  5. In the Host identifier list, select ShapeAppCSharp. This list is automatically populated with the host IDs of host applications that have been registered.

  6. Click Next to move to the next page in the wizard.

The next page of the wizard enables you to specify a host item and to associate icons with the host and host item.

To specify the host item

  1. In the Proxy assembly name box, click the ellipsis (…) button and navigate to the proxy assembly (ShapeAppCSharpProxy.dll).

  2. In the Base type list, select Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.ApplicationEntryPoint. This list is automatically populated with classes that are identified as entry points in the proxy assembly.

  3. In the Host item name box, type ThisApplication. This is the name of the host item that determines the name of the code file. For example, ThisApplication.cs and ThisApplication.vb.

  4. Leave the Icon image list box blank. Typically you would navigate to an image list that is used by the project items. Default icons are used in this walkthrough.

    Note

    If you specify an icon image list, these icons are not added to your project. Instead, the full path to the icons is stored. This path, and all paths that you supply in the wizard, will be used when the project template is deployed. If add-in computers might have different file locations, you must modify the project template so that it uses correct paths. For example, you can replace paths with variables. For more information about variables, see Project Template Generation Tool (Projectgen.exe).

  5. Leave the Host icon index list, Host item icon index list, and Host item open folder icon index list blank. These icons typically represent the icons for the host, the host item, and the host item in its expanded state that will appear in Project Explorer. For this walkthrough, use the default icons.

  6. Click Next to move to the next page in the wizard.

The next page in the wizard enables you to specify project properties. The References section is automatically populated with references that are required by Visual Studio Tools for Applications, which cannot be removed. You can add and remove additional references.

Note

The proxy assembly that you specified is also automatically added as a required reference. If the proxy contains other references, these references are not automatically added. You must add these additional references manually.

To specify project properties

  1. In the Debug exe box, click the ellipsis (…) button and navigate to the application path drive:\ShapeAppSamples\ShapeAppCSharp\core\bin\Debug\ShapeAppCSharp.exe. This box is used to indicate which application to run when the add-in developer presses F5 to start debugging the application.

  2. Leave the Debug command line box blank. This box is typically used to identify replacement variables. For more information, see Project Template Generation Tool (Projectgen.exe).

  3. Leave the In-process host box blank. The ShapeAppCSharp sample does not use an in-process host. For more information, see Creating In-Process Hosts.

  4. Click Next to move to the last page in the wizard.

The last page of the wizard enables you to generate the project template by indicating a path for the project templates, optionally registering the template, and saving the project template descriptor file.

To generate the project template

  1. Select the Create project template check box, if it is not already selected, and then click the ellipsis (…) button and navigate to the template path that you specified when you registered the host application. In this case, the path should be drive:\ShapeAppSamples\ShapeAppCSharp\Templates.

    Note

    The wizard adds subfolders under the directory that you specify. The subfolders are Language\LocaleID\HostID\. The project template is named TemplateName.zip.

  2. Select the Register template with host application check box.

  3. Select the Save project template descriptor file check box, if it is not already selected, and then click the ellipsis (…) button and navigate to drive:\ShapeAppSamples\ShapeAppCSharp\.

  4. In the File name box of the Save As dialog box, type ProjectDescriptor and then click Save.

  5. Click Finish to complete the wizard.

  6. After the project templates have been registered, click OK on the Registering Project Templates dialog box.

Testing the Project Templates

Because you selected the Register template with host application check box in the wizard, the templates were automatically registered and are available when you run the ShapeAppCSharp application.

To run the ShapeAppCSharp application

  1. In the Visual Studio 2008 Command Prompt window, type the following command and then press ENTER:

    vsta /hostid ShapeAppCSharp
    

    The Visual Studio Tools for Applications integrated development environment (IDE) opens.

  2. On the File menu, click New Project.

  3. In the New Project dialog box, select the Visual C# node.

  4. In the Templates pane, select ShapeAppCSharp Add-in.

  5. Verify that ShapeAppCSharp1 appears in the Name box, and click OK.

    The ShapeAppCSharp1 add-in project opens in the IDE.

Next Steps

If you performed this walkthrough as part of the comprehensive series of walkthroughs for the ShapeApp sample, return to Walkthrough: Integrating Visual Studio Tools for Applications with ShapeApp.

If you performed this walkthrough as a stand-alone walkthrough, you might want to learn how to modify an application to enable add-ins. For more information, see Walkthrough: Modifying an Application to Load Add-Ins.

See Also

Tasks

Walkthrough: Integrating Visual Studio Tools for Applications with ShapeApp

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

Walkthrough: Modifying an Application to Load Add-Ins

Concepts

Creating Project Templates (Visual Studio Tools for Applications)

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

Reference

Descriptor Schema for Projectgen.exe

Project Template Generation Tool (Projectgen.exe)