Share via


Including Existing Templates in a VSIX Container

In the Visual Studio 2008 SDK, we have several samples (most notably, IronPythonIntegration) set up to use the ZipProject, ZipItem, and VSTemplate build actions to create template zip files.

IronPython templates

Last week, I published a post on the Visual Studio Blog discussing how you could build templates from source files and package them up in a VSIX container using the new templates in the Visual Studio 2010 SDK.

We’ve been hearing questions about how to take an existing project (updated from Visual Studio 2008, still using ZipProject/ZipItem) and include the built zip files in the VSIX container.

Unfortunately, this doesn’t happen automatically for you. The reason is that the zip files are not specified as input files for building the VSIX container in the VSSDK build targets.

Fortunately, since MSBuild is a highly extensible system, we can make up for this with a little bit of project customization. Simply add the following to your C#/VB project file to get your existing templates included in the VSIX container:

 <PropertyGroup>
    <GetVsixSourceItemsDependsOn>$(GetVsixSourceItemsDependsOn);GetVsixTemplateItems</GetVsixSourceItemsDependsOn>
</PropertyGroup>
<Target Name="GetVsixTemplateItems" DependsOnTargets="ZipProjects;ZipItems">
    <ItemGroup>
        <VSIXSourceItem Include="@(IntermediateZipItem)">
            <VSIXSubPath>ItemTemplates\%(IntermediateZipItem.Language)\%(IntermediateZipItem.OutputSubPath)\%(IntermediateZipItem.Culture)</VSIXSubPath>
        </VSIXSourceItem>
        <VSIXSourceItem Include="@(IntermediateZipProject)">
            <VSIXSubPath>ProjectTemplates\%(IntermediateZipProject.Language)\%(IntermediateZipProject.OutputSubPath)\%(IntermediateZipProject.Culture)</VSIXSubPath>
        </VSIXSourceItem>
    </ItemGroup>
</Target>

You will also need to add the following lines (as appropriate) to your source.extension.vsixmanifest:

 <Content>
    <ProjectTemplate>ProjectTemplates</ProjectTemplate>
    <ItemTemplate>ItemTemplates</ItemTemplate>
</Content>

These lines each declare a root folder in your VSIX file that VS should examine for template files. Project template zip files will be placed in the ProjectTemplates folder inside the VSIX file. Item template zip files will be placed in (you guessed it)…the ItemTemplates folder inside the VSIX file.

Comments

  • Anonymous
    September 07, 2010
    You legend - I have spent the best part of five hours failing to work out how to do this, and your solution works perfectly.