Share via


Deploying Project and Project Item Templates

VSPackage products can include custom templates for projects and project items that appear in the Visual Basic 2008 New Project dialog box. This topic highlights how you use Windows Installer to install template files.

For more information about templates, see Visual Studio Templates. For more information about creating templates, see Creating Project and Item Templates.

Template directories and files

As discussed in How to: Locate and Organize Project and Item Templates, you can install templates into either the Installed Templates or Custom Templates directories. The Custom Templates directory is under the setting of the current user, which is problematic for an installer. It violates Windows Installer best practices for components and directories. (For more information, see the note under Directory_ in Component Table [Windows Installer].) That leaves the Installed Templates directory, which is appropriate for a VSPackage that offers custom templates.

The first step is to use Windows Installer's AppSearch action with a RegLocator entry to locate the templates directories of an installation of Visual Basic 2008, as shown in the following tables:

RegLocator table row to locate EnvironmentDirectory install directory for Visual Studio 2005 SDK

Signature_

Root

Key

Name

Type

RL_EnvironmentDir_2005

2

SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS

EnvironmentDirectory

0

AppSearch table row for RegLocator table row

Property

Signature_

ENVDIR_2005

RL_EnvironmentDir_2005

After the AppSearch action, the ENVDIR_2005 property will contain a value similar to C:\VS2008\Common7\IDE\. The template directories — named ProjectTemplates and ItemTemplates — are subdirectories of that directory. As discussed in How to: Locate and Organize Project and Item Templates, templates themselves are located in additional subdirectories identifying the language and locale to which they apply.

Directory table entries can refer to a property as a parent directory. Consequently, you can use ENVDIR_2005 as the parent of other Directory table entries to point to the template directories and subdirectories under them. For example:

Sample Directory table rows for template directories

Directory

Directory_Parent

DefaultDir

TARGETDIR

 

SourceDir

ENVDIR_2005

TARGETDIR

EnvDir

ProjectTemplates

ENVDIR_2005

Projec~1|ProjectTemplates

ProjectTemplatesCSharp

ProjectTemplates

CSharp

ProjectTemplatesCSharp1033

ProjectTemplatesCSharp

1033

ItemTemplates

ENVDIR_2005

ItemTe~1|ItemTemplates

ItemTemplatesCSharp

ItemTemplates

CSharp

ItemTemplatesCSharp1033

ItemTemplatesCSharp

1033

Given those Directory table rows, if ENVDIR_2005 is set to C:\VS2005\Common7\IDE\, ProjectTemplatesCSharp1033 points to C:\VS2005\Common7\IDE\ProjectTemplates\CSharp\1033\. Components then have their Directory_ column pointing to the appropriate Directory table row.

Example

If you use the Windows Installer XML Toolset, you can create a Toolset source file that sets up the AppSearch, RegLocator, and Directory table entries discussed above:

<?xml version='1.0'?>
<Wix xmlns='https://schemas.microsoft.com/wix/2003/01/wi'>
...
<Property Id='ENVDIR_2005'>
  <RegistrySearch 
    Id="RL_EnvironmentDir_2005" 
    Root="HKLM" 
    Key="SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS" 
    Name="EnvironmentDirectory" 
    Type="directory" />
</Property>

<Directory Id='TARGETDIR' Name='SourceDir'>
  <Directory Id='ENVDIR_2005' Name='EnvDir'>
    <Directory Id='ProjectTemplates' 
      LongName='ProjectTemplates' 
      Name='Projec~1'>
      <Directory Id='ProjectTemplatesCSharp' Name='CSharp'>
        <Directory Id='ProjectTemplatesCSharp1033' Name='1033'>
          <Component Id='MyProjectTemplateCSharp2005' 
            Guid='34B9D9B1-F02D-4191-9CCE-DF3AF3FB571F' 
            DiskId='1'>
            <File Id='MyProjectTemplateCSharp2005' 
              LongName='MyProjectTemplateCSharp2005.zip' 
              Name='MyProj~1.zip' 
              src='./MyProjectTemplateCSharp2005.zip' />
          </Component>
        </Directory>
      </Directory>
    </Directory>
    <Directory Id='ItemTemplates' 
      LongName='ItemTemplates' 
      Name='ItemTe~1'>
      <Directory Id='ItemTemplatesCSharp' Name='CSharp'>
        <Directory Id='ItemTemplatesCSharp1033' Name='1033'>
          <Component Id='MyItemTemplateCSharp2005' 
            Guid='63373730-BF26-45e9-9961-4F8218CC0DD5' 
            DiskId='1'>
            <File Id='MyItemTemplateCSharp2005' 
              LongName='MyItemTemplateCSharp2005.zip' 
              Name='MyItem~1.zip' 
              src='./MyItemTemplateCSharp2005.zip' />
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Directory>
</Directory>
...
</Wix>

See Also

Other Resources

Installing VSPackages By Using Windows Installer