Skip to content

Commit 410bde4

Browse files
authored
chore(sdk): remove unused template zipping, keep VsixTemplateReference (#41)
* chore(sdk): remove unused template zipping, keep VsixTemplateReference - Remove VsixTemplateZip item type and related targets (VSSDK handles template packaging natively when Content entries are in manifest) - Keep VsixTemplateReference for cross-project templates (copies folders from referenced projects to local ProjectTemplates/ItemTemplates) - Add proper VSIXSubPath metadata so copied templates are placed at correct paths in the VSIX - Update E2E tests: remove PreBuiltZip, add Reference and ReferenceManual - Update workflow to verify new template reference tests - Update documentation to reflect simplified template handling Closes #39 * fix(sdk): include auto-discovered templates in VSIX Add Content items for auto-discovered project and item templates so they are included in the VSIX package. The removal of template zipping also removed the mechanism that added templates to the VSIX, which broke auto-discovery scenarios. * docs(templates): clarify SDK handles template packaging Update documentation to accurately reflect that this SDK includes template files in the VSIX, not VSSDK. The manifest Content entries are for VS template registration, not file inclusion.
1 parent b16ced4 commit 410bde4

File tree

27 files changed

+362
-352
lines changed

27 files changed

+362
-352
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ jobs:
7575
- name: Build E2E.Templates.AutoDiscovery
7676
run: dotnet build tests/e2e/E2E.Templates.AutoDiscovery/E2E.Templates.AutoDiscovery.csproj -c Release
7777

78-
- name: Build E2E.Templates.PreBuiltZip
79-
run: dotnet build tests/e2e/E2E.Templates.PreBuiltZip/E2E.Templates.PreBuiltZip.csproj -c Release
78+
- name: Build E2E.Templates.Reference
79+
run: dotnet build tests/e2e/E2E.Templates.Reference/E2E.Templates.Reference.csproj -c Release
80+
81+
- name: Build E2E.Templates.ReferenceManual
82+
run: dotnet build tests/e2e/E2E.Templates.ReferenceManual/E2E.Templates.ReferenceManual.csproj -c Release
8083

8184
- name: Build E2E.Templates.ManualWithSubPath
8285
run: dotnet build tests/e2e/E2E.Templates.ManualWithSubPath/E2E.Templates.ManualWithSubPath.csproj -c Release
@@ -106,6 +109,28 @@ jobs:
106109
if ($files -notcontains "NewClass.vstemplate") { throw "Missing ItemTemplates/NewClass/NewClass.vstemplate" }
107110
Write-Host "E2E.Templates.AutoDiscovery VSIX verified successfully"
108111
112+
- name: Verify E2E.Templates.Reference VSIX
113+
run: |
114+
$vsix = "tests/e2e/E2E.Templates.Reference/bin/Release/net472/E2E.Templates.Reference.vsix"
115+
if (!(Test-Path $vsix)) { throw "VSIX not found: $vsix" }
116+
Expand-Archive -Path $vsix -DestinationPath "tests/e2e/E2E.Templates.Reference/vsix-contents" -Force
117+
$files = Get-ChildItem -Path "tests/e2e/E2E.Templates.Reference/vsix-contents" -Recurse | Select-Object -ExpandProperty Name
118+
# Verify templates copied from referenced project are included
119+
if ($files -notcontains "RefProject.vstemplate") { throw "Missing ProjectTemplates/ProjectTemplate/RefProject.vstemplate" }
120+
if ($files -notcontains "RefItem.vstemplate") { throw "Missing ItemTemplates/ItemTemplate/RefItem.vstemplate" }
121+
Write-Host "E2E.Templates.Reference VSIX verified successfully"
122+
123+
- name: Verify E2E.Templates.ReferenceManual VSIX
124+
run: |
125+
$vsix = "tests/e2e/E2E.Templates.ReferenceManual/bin/Release/net472/E2E.Templates.ReferenceManual.vsix"
126+
if (!(Test-Path $vsix)) { throw "VSIX not found: $vsix" }
127+
Expand-Archive -Path $vsix -DestinationPath "tests/e2e/E2E.Templates.ReferenceManual/vsix-contents" -Force
128+
$files = Get-ChildItem -Path "tests/e2e/E2E.Templates.ReferenceManual/vsix-contents" -Recurse | Select-Object -ExpandProperty Name
129+
# Verify templates copied from referenced project are included (manual manifest)
130+
if ($files -notcontains "RefProject.vstemplate") { throw "Missing ProjectTemplates/ProjectTemplate/RefProject.vstemplate" }
131+
if ($files -notcontains "RefItem.vstemplate") { throw "Missing ItemTemplates/ItemTemplate/RefItem.vstemplate" }
132+
Write-Host "E2E.Templates.ReferenceManual VSIX verified successfully"
133+
109134
- name: Verify E2E.AllFeatures VSIX
110135
run: |
111136
$vsix = "tests/e2e/E2E.AllFeatures/bin/Release/net472/E2E.AllFeatures.vsix"

docs/templates.md

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,30 @@ This document explains how to include Visual Studio project templates and item t
66

77
The built-in VSIX Manifest Designer in Visual Studio cannot enumerate SDK-style projects when adding template assets. This is because the designer uses legacy DTE extenders that are registered for the old project system, not the Common Project System (CPS) used by SDK-style projects.
88

9-
Additionally, SDK-style projects don't define the `TemplateProjectOutputGroup` and `ItemTemplateOutputGroup` MSBuild output groups that VSSDK expects for template assets.
9+
This SDK provides MSBuild-based template support that works around these limitations by:
10+
- Auto-discovering templates in standard folders
11+
- Supporting cross-project template references
12+
- Providing validation warnings for missing manifest Content entries
1013

11-
This SDK provides MSBuild-based template support that bypasses these limitations entirely.
14+
## How It Works
15+
16+
This SDK handles template packaging by:
17+
18+
1. **Auto-discovering** templates in `ProjectTemplates/` and `ItemTemplates/` folders
19+
2. **Including template files** in the VSIX package automatically
20+
3. **Supporting cross-project template references** for including templates from other SDK-style projects
21+
4. **Providing validation warnings** if your manifest is missing required Content entries
22+
23+
Your manifest must contain `<Content><ProjectTemplate/></Content>` entries for Visual Studio to register and display templates. The SDK includes the template files in the VSIX; the manifest entries tell VS how to find and register them.
1224

1325
## Item Types
1426

15-
The SDK provides four item types for including templates:
27+
The SDK provides the following item types for templates:
1628

1729
| Item Type | Description |
1830
|-----------|-------------|
19-
| `VsixProjectTemplate` | A folder containing a `.vstemplate` file for a project template |
20-
| `VsixItemTemplate` | A folder containing a `.vstemplate` file for an item template |
21-
| `VsixTemplateZip` | A pre-built template zip file |
31+
| `VsixProjectTemplate` | (Auto-discovered) A folder containing a `.vstemplate` file for a project template |
32+
| `VsixItemTemplate` | (Auto-discovered) A folder containing a `.vstemplate` file for an item template |
2233
| `VsixTemplateReference` | Reference a template folder from another project |
2334

2435
## Auto-Discovery
@@ -45,10 +56,12 @@ MyExtension/
4556
MyClass.cs
4657
```
4758

48-
With this structure, no additional configuration is needed. The SDK will:
59+
With this structure, minimal configuration is needed. The SDK will:
4960
1. Find the templates automatically
50-
2. Zip each template folder during build
51-
3. Include the zips in the VSIX at `ProjectTemplates/` and `ItemTemplates/`
61+
2. Include all template files in the VSIX
62+
3. Warn if `<Content>` entries are missing from the manifest
63+
64+
You need to add the Content entries to your manifest manually (see Manifest Configuration below).
5265

5366
### Disabling Auto-Discovery
5467

@@ -71,33 +84,9 @@ To use different folder names:
7184
</PropertyGroup>
7285
```
7386

74-
## Manual Template Configuration
75-
76-
### Folder-Based Templates
77-
78-
If your templates are in non-standard locations, add them explicitly:
79-
80-
```xml
81-
<ItemGroup>
82-
<VsixProjectTemplate Include="MyTemplates\ConsoleApp" />
83-
<VsixItemTemplate Include="MyTemplates\NewClass" />
84-
</ItemGroup>
85-
```
86-
87-
### Pre-Built Template Zips
88-
89-
If you have pre-built template zip files:
90-
91-
```xml
92-
<ItemGroup>
93-
<VsixTemplateZip Include="Templates\MyTemplate.zip" TemplateType="Project" />
94-
<VsixTemplateZip Include="Templates\MyItem.zip" TemplateType="Item" />
95-
</ItemGroup>
96-
```
97-
98-
### Template References
87+
## Cross-Project Template References
9988

100-
To include a template from another project in your solution:
89+
When you have templates in a separate SDK-style project that the VSIX Manifest Designer cannot enumerate, use `VsixTemplateReference`:
10190

10291
```xml
10392
<ItemGroup>
@@ -107,6 +96,10 @@ To include a template from another project in your solution:
10796
</ItemGroup>
10897
```
10998

99+
The SDK will:
100+
1. Copy the template folder from the referenced project to your local `ProjectTemplates/` or `ItemTemplates/` folder
101+
2. Include the copied template files in the VSIX
102+
110103
The `TemplatePath` is relative to the referenced project's directory.
111104

112105
## Manifest Configuration
@@ -120,24 +113,10 @@ Visual Studio requires `<Content>` entries in your `.vsixmanifest` to register t
120113
</Content>
121114
```
122115

123-
The SDK will emit warnings if you have templates defined but missing manifest entries:
116+
The SDK will emit warnings if you have templates but missing manifest entries:
124117
- **VSIXSDK011**: Project templates defined but no `<ProjectTemplate>` in manifest
125118
- **VSIXSDK012**: Item templates defined but no `<ItemTemplate>` in manifest
126119

127-
## Target Subfolders
128-
129-
To organize templates into subfolders within the VSIX:
130-
131-
```xml
132-
<ItemGroup>
133-
<!-- Will be placed at ProjectTemplates/CSharp/ -->
134-
<VsixProjectTemplate Include="ProjectTemplates\MyTemplate" TargetSubPath="CSharp" />
135-
136-
<!-- Will be placed at ItemTemplates/Web/ -->
137-
<VsixItemTemplate Include="ItemTemplates\MyItem" TargetSubPath="Web" />
138-
</ItemGroup>
139-
```
140-
141120
## Complete Example
142121

143122
### Project File
@@ -149,7 +128,9 @@ To organize templates into subfolders within the VSIX:
149128
<Version>1.0.0</Version>
150129
</PropertyGroup>
151130

152-
<!-- Templates are auto-discovered, but you can add more explicitly -->
131+
<!-- Templates in ProjectTemplates/ and ItemTemplates/ are auto-discovered -->
132+
133+
<!-- Include templates from another SDK-style project -->
153134
<ItemGroup>
154135
<VsixTemplateReference Include="..\SharedTemplates\SharedTemplates.csproj"
155136
TemplateType="Project"
@@ -161,6 +142,8 @@ To organize templates into subfolders within the VSIX:
161142

162143
### Manifest File
163144

145+
Add the `<Content>` entries for your templates:
146+
164147
```xml
165148
<?xml version="1.0" encoding="utf-8"?>
166149
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011">
@@ -206,7 +189,6 @@ To organize templates into subfolders within the VSIX:
206189

207190
| Code | Description |
208191
|------|-------------|
209-
| VSIXSDK010 | `VsixTemplateZip` item missing `TemplateType` metadata |
210192
| VSIXSDK011 | Project templates defined but no `<ProjectTemplate>` in manifest |
211193
| VSIXSDK012 | Item templates defined but no `<ItemTemplate>` in manifest |
212194
| VSIXSDK013 | `VsixTemplateReference` item missing `TemplateType` metadata |
@@ -217,14 +199,17 @@ To organize templates into subfolders within the VSIX:
217199
### Templates not appearing in Visual Studio
218200

219201
1. Ensure your manifest has the appropriate `<Content>` entries
220-
2. Check that the template zip files are included in the VSIX (open the .vsix as a zip)
202+
2. Check that the template folders are included in the VSIX (open the .vsix as a zip)
221203
3. Verify the `.vstemplate` file has correct `<ProjectType>` or `<TemplateGroupID>`
222204
4. Reset the Visual Studio template cache: delete `%LocalAppData%\Microsoft\VisualStudio\<version>\ComponentModelCache`
223205

224206
### Build errors about missing template folders
225207

226208
Ensure the template folder exists and contains a `.vstemplate` file. For `VsixTemplateReference`, verify the `TemplatePath` is correct relative to the referenced project.
227209

228-
### Templates in wrong location in VSIX
210+
### Cross-project templates not working
229211

230-
Check the `TargetSubPath` metadata if you're using custom paths. By default, templates are placed directly in `ProjectTemplates/` or `ItemTemplates/`.
212+
1. Verify the referenced project path is correct
213+
2. Check that `TemplateType` is set to `Project` or `Item`
214+
3. Ensure `TemplatePath` points to a folder containing a `.vstemplate` file
215+
4. The template folder will be copied to your local `ProjectTemplates/` or `ItemTemplates/` folder during build

src/CodingWithCalvin.VsixSdk/Sdk/Sdk.Vsix.Templates.props

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
<!--
33
CodingWithCalvin.VsixSdk - Sdk.Vsix.Templates.props
44
5-
Template support for VSIX projects. Defines item types for including
6-
project templates and item templates in VSIX packages.
5+
Template support for VSIX projects. Defines properties and item types
6+
for including project templates and item templates in VSIX packages.
77
8-
This bypasses the broken VSIX Manifest Designer which cannot enumerate
9-
SDK-style projects for template assets.
8+
Features:
9+
- Auto-discovery of templates in ProjectTemplates/ and ItemTemplates/ folders
10+
- Cross-project template references via VsixTemplateReference
11+
- Validation warnings for missing manifest Content entries
12+
13+
Note: VSSDK handles the actual template packaging. This SDK provides
14+
discovery, validation, and convenience features on top of VSSDK.
1015
-->
1116

1217
<PropertyGroup>
@@ -28,23 +33,22 @@
2833
<!--
2934
Item type definitions:
3035
31-
VsixProjectTemplate - A folder containing a .vstemplate file for a project template
32-
Will be zipped and included in the VSIX at ProjectTemplates/
33-
34-
VsixItemTemplate - A folder containing a .vstemplate file for an item template
35-
Will be zipped and included in the VSIX at ItemTemplates/
36+
VsixProjectTemplate - (Auto-discovered) A folder containing a .vstemplate file for a project template.
37+
Discovered automatically in the ProjectTemplates/ folder.
38+
VSSDK packages these based on manifest Content entries.
3639
37-
VsixTemplateZip - A pre-built template zip file to include directly
38-
Specify TemplateType="Project" or TemplateType="Item"
40+
VsixItemTemplate - (Auto-discovered) A folder containing a .vstemplate file for an item template.
41+
Discovered automatically in the ItemTemplates/ folder.
42+
VSSDK packages these based on manifest Content entries.
3943
40-
VsixTemplateReference - Reference a template folder from another project
41-
Specify TemplateType="Project" or TemplateType="Item"
42-
TemplatePath is relative to the referenced project directory
44+
VsixTemplateReference - Reference a template folder from another project.
45+
Useful when the VSIX Manifest Designer cannot enumerate SDK-style projects.
46+
Templates are copied to the local template folder so VSSDK can package them.
4347
4448
Usage:
45-
<VsixProjectTemplate Include="ProjectTemplates\MyTemplate" />
46-
<VsixItemTemplate Include="ItemTemplates\MyItem" />
47-
<VsixTemplateZip Include="Templates\PreBuilt.zip" TemplateType="Project" />
49+
(Templates in ProjectTemplates/ and ItemTemplates/ are auto-discovered)
50+
51+
(Reference templates from another SDK-style project)
4852
<VsixTemplateReference Include="..\MyTemplateProject\MyTemplateProject.csproj"
4953
TemplateType="Project"
5054
TemplatePath="Templates\MyProjectTemplate" />
@@ -61,13 +65,6 @@
6165
<TargetSubPath></TargetSubPath>
6266
</VsixItemTemplate>
6367

64-
<VsixTemplateZip>
65-
<!-- Must specify Project or Item -->
66-
<TemplateType></TemplateType>
67-
<!-- Optional subfolder within the template type folder -->
68-
<TargetSubPath></TargetSubPath>
69-
</VsixTemplateZip>
70-
7168
<VsixTemplateReference>
7269
<!-- Must specify Project or Item -->
7370
<TemplateType></TemplateType>

0 commit comments

Comments
 (0)