-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSdk.Vsix.targets
More file actions
258 lines (214 loc) · 11.7 KB
/
Sdk.Vsix.targets
File metadata and controls
258 lines (214 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<Project>
<!--
CodingWithCalvin.VsixSdk - Sdk.Vsix.targets
VSIX-specific targets. Can be imported standalone or as part of the full SDK.
-->
<!--
Default item includes for VSIX projects
These can be disabled with EnableDefaultVsixItems=false
-->
<ItemGroup Condition="'$(EnableDefaultVsixItems)' != 'false' and '$(EnableDefaultItems)' != 'false'">
<!-- Include VSCT files (Visual Studio Command Table) -->
<VSCTCompile Include="**/*.vsct"
Condition="'$(EnableDefaultVsctItems)' != 'false'"
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)">
<ResourceName>$(VSCTResourceName)</ResourceName>
</VSCTCompile>
<!-- Include VSPackage resource files -->
<EmbeddedResource Include="**/VSPackage.resx"
Condition="'$(EnableDefaultVSPackageResourceItems)' != 'false'"
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)">
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
</EmbeddedResource>
<!-- Include localized VSPackage resources -->
<EmbeddedResource Include="**/VSPackage.*.resx"
Condition="'$(EnableDefaultVSPackageResourceItems)' != 'false'"
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);**/VSPackage.resx">
<MergeWithCTO>true</MergeWithCTO>
<DependentUpon>VSPackage.resx</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<!-- Detect the source manifest location -->
<_SourceVsixManifestPath Condition="'$(_SourceVsixManifestPath)' == '' and Exists('$(MSBuildProjectDirectory)\source.extension.vsixmanifest')">$(MSBuildProjectDirectory)\source.extension.vsixmanifest</_SourceVsixManifestPath>
<_SourceVsixManifestPath Condition="'$(_SourceVsixManifestPath)' == '' and Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).vsixmanifest')">$(MSBuildProjectDirectory)\$(MSBuildProjectName).vsixmanifest</_SourceVsixManifestPath>
</PropertyGroup>
<!--
Add VSIX manifest and VSCT files as AdditionalFiles for source generators.
The generators use these to produce VsixInfo.g.cs and *Vsct.g.cs files.
-->
<ItemGroup>
<!-- Add VSIX manifest for VsixInfoGenerator -->
<AdditionalFiles Include="$(_SourceVsixManifestPath)" Condition="'$(_SourceVsixManifestPath)' != '' and Exists('$(_SourceVsixManifestPath)')" />
<!-- Add VSCT files for VsctGuidsGenerator -->
<AdditionalFiles Include="@(VSCTCompile)" />
<!-- Keep source manifest visible in Solution Explorer for editing -->
<None Include="$(_SourceVsixManifestPath)" Condition="'$(_SourceVsixManifestPath)' != '' and Exists('$(_SourceVsixManifestPath)')">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<!--
Version override support
Usage: dotnet build -p:SetVsixVersion=2.5.0
When SetVsixVersion is specified on the command line:
1. Updates the source manifest with the new version
2. Spawns a new MSBuild process that re-evaluates and builds with the updated manifest
3. Creates a sentinel file to prevent the outer build from overwriting the VSIX
This is necessary because VSSDK reads the manifest during evaluation phase,
before any targets run. A new process re-evaluates and reads the updated manifest.
Note: Use SetVsixVersion (not VsixVersion) because VsixVersion has a default value.
-->
<PropertyGroup>
<_VsixVersionSentinel>$(IntermediateOutputPath)_vsix_version_build.sentinel</_VsixVersionSentinel>
</PropertyGroup>
<Target Name="BuildWithVsixVersion"
BeforeTargets="PrepareForBuild"
Condition="'$(SetVsixVersion)' != '' and '$(_VsixVersionBuildInProgress)' != 'true' and '$(_SourceVsixManifestPath)' != '' and Exists('$(_SourceVsixManifestPath)')">
<PropertyGroup>
<_VsixNsForPoke><Namespace Prefix='vsix' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011'/></_VsixNsForPoke>
</PropertyGroup>
<!-- Update the source manifest -->
<XmlPoke XmlInputPath="$(_SourceVsixManifestPath)"
Query="/vsix:PackageManifest/vsix:Metadata/vsix:Identity/@Version"
Value="$(SetVsixVersion)"
Namespaces="$(_VsixNsForPoke)" />
<Message Importance="high" Text="Updated VSIX manifest version to $(SetVsixVersion)" />
<!-- Create sentinel to mark that inner build will produce the correct VSIX -->
<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists('$(IntermediateOutputPath)')" />
<WriteLinesToFile File="$(_VsixVersionSentinel)" Lines="$(SetVsixVersion)" Overwrite="true" />
<!-- Spawn new MSBuild process that will re-evaluate and read the updated manifest -->
<Exec Command="dotnet build "$(MSBuildProjectFullPath)" -c $(Configuration) -p:_VsixVersionBuildInProgress=true --no-restore"
WorkingDirectory="$(MSBuildProjectDirectory)" />
<Message Importance="high" Text="VSIX build with version $(SetVsixVersion) completed." />
</Target>
<!-- Skip CreateVsixContainer when sentinel exists (outer build - inner build already created VSIX) -->
<Target Name="_SkipVsixContainerForOuterBuild"
BeforeTargets="CreateVsixContainer"
Condition="'$(SetVsixVersion)' != '' and '$(_VsixVersionBuildInProgress)' != 'true' and Exists('$(_VsixVersionSentinel)')">
<Message Importance="high" Text="Skipping VSIX creation in outer build (already created by inner build)." />
<!-- Clear the inputs so CreateVsixContainer has nothing to do -->
<ItemGroup>
<VSIXSourceItem Remove="@(VSIXSourceItem)" />
</ItemGroup>
</Target>
<!-- Clean up sentinel after outer build completes -->
<Target Name="_CleanupVsixVersionSentinel"
AfterTargets="Build"
Condition="'$(SetVsixVersion)' != '' and '$(_VsixVersionBuildInProgress)' != 'true' and Exists('$(_VsixVersionSentinel)')">
<Delete Files="$(_VsixVersionSentinel)" />
</Target>
<!--
Generate Publish Manifest (publish.manifest.json)
Creates a VS Marketplace publish manifest from project properties and VSIX manifest
-->
<Target Name="GeneratePublishManifest"
AfterTargets="Build"
Condition="'$(GeneratePublishManifest)' == 'true' and '$(_SourceVsixManifestPath)' != '' and Exists('$(_SourceVsixManifestPath)')">
<PropertyGroup>
<_VsixNsForPeek><Namespace Prefix='vsix' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011'/></_VsixNsForPeek>
</PropertyGroup>
<!-- Read Publisher from VSIX manifest -->
<XmlPeek XmlInputPath="$(_SourceVsixManifestPath)"
Query="/vsix:PackageManifest/vsix:Metadata/vsix:Identity/@Publisher"
Namespaces="$(_VsixNsForPeek)">
<Output TaskParameter="Result" PropertyName="_VsixPublisher" />
</XmlPeek>
<!-- Read MoreInfo (repo URL) from VSIX manifest -->
<XmlPeek XmlInputPath="$(_SourceVsixManifestPath)"
Query="/vsix:PackageManifest/vsix:Metadata/vsix:MoreInfo/text()"
Namespaces="$(_VsixNsForPeek)">
<Output TaskParameter="Result" PropertyName="_VsixMoreInfo" />
</XmlPeek>
<!-- Read Tags (categories) from VSIX manifest -->
<XmlPeek XmlInputPath="$(_SourceVsixManifestPath)"
Query="/vsix:PackageManifest/vsix:Metadata/vsix:Tags/text()"
Namespaces="$(_VsixNsForPeek)">
<Output TaskParameter="Result" PropertyName="_VsixTags" />
</XmlPeek>
<!-- Convert comma-separated tags to JSON array format -->
<PropertyGroup>
<!-- First trim spaces after commas, then replace commas with JSON array separators -->
<_VsixTagsNormalized>$(_VsixTags.Replace(', ', ','))</_VsixTagsNormalized>
<_CategoriesJson>$(_VsixTagsNormalized.Replace(',', '", "'))</_CategoriesJson>
<_CategoriesJson>"$(_CategoriesJson)"</_CategoriesJson>
<_QnAValue Condition="'$(VsixPublishQnA)' == 'true'">true</_QnAValue>
<_QnAValue Condition="'$(VsixPublishQnA)' != 'true'">false</_QnAValue>
<_RepoLine Condition="'$(_VsixMoreInfo)' != ''">,
"repo": "$(_VsixMoreInfo)"</_RepoLine>
<_RepoLine Condition="'$(_VsixMoreInfo)' == ''"></_RepoLine>
</PropertyGroup>
<!-- Write the publish manifest JSON -->
<PropertyGroup>
<_PublishManifestContent><![CDATA[{
"$schema": "http://json.schemastore.org/vsix-publish",
"categories": [
$(_CategoriesJson)
],
"identity": {
"internalName": "$(MSBuildProjectName)"
},
"overview": "$(VsixPublishOverview)",
"publisher": "$(_VsixPublisher)",
"qna": $(_QnAValue)$(_RepoLine)
}]]></_PublishManifestContent>
</PropertyGroup>
<WriteLinesToFile File="$(MSBuildProjectDirectory)\publish.manifest.json"
Lines="$(_PublishManifestContent)"
Overwrite="true" />
<Message Importance="high" Text="Generated publish manifest: $(MSBuildProjectDirectory)\publish.manifest.json" />
</Target>
<!--
Target to validate VSIX project configuration
Runs early in the build to catch common mistakes
-->
<Target Name="ValidateVsixConfiguration" BeforeTargets="BeforeBuild">
<!-- Warn if targeting x86 (VS 2022 is 64-bit) -->
<Warning Condition="'$(PlatformTarget)' == 'x86'"
Text="Visual Studio 2022 is 64-bit. Consider changing PlatformTarget to 'AnyCPU'." />
<!-- Warn if no VSIX manifest found -->
<Warning Condition="!Exists('$(MSBuildProjectDirectory)\source.extension.vsixmanifest') and !Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).vsixmanifest')"
Text="No .vsixmanifest file found. VSIX projects require a manifest file." />
</Target>
<!--
Generate launchSettings.json for F5 debugging
Only runs when building inside Visual Studio and the file doesn't exist
This configures VS to launch devenv.exe with the experimental instance
-->
<Target Name="GenerateLaunchSettings"
BeforeTargets="BeforeBuild"
Condition="'$(BuildingInsideVisualStudio)' == 'true' and '$(DevEnvDir)' != '' and !Exists('$(MSBuildProjectDirectory)\Properties\launchSettings.json')">
<PropertyGroup>
<_LaunchSettingsContent><![CDATA[{
"profiles": {
"Start Experimental Instance": {
"commandName": "Executable",
"executablePath": "$(DevEnvDir)devenv.exe",
"commandLineArgs": "/rootSuffix Exp"
}
}
}]]></_LaunchSettingsContent>
</PropertyGroup>
<MakeDir Directories="$(MSBuildProjectDirectory)\Properties" Condition="!Exists('$(MSBuildProjectDirectory)\Properties')" />
<WriteLinesToFile File="$(MSBuildProjectDirectory)\Properties\launchSettings.json"
Lines="$(_LaunchSettingsContent)"
Overwrite="true" />
<Message Importance="high" Text="Generated Properties/launchSettings.json for F5 debugging" />
</Target>
<!--
Import VSSDK targets if available
This is the key integration point with Microsoft.VSSDK.BuildTools
-->
<PropertyGroup>
<!-- Allow users to skip VSSDK import -->
<ImportVsSDKTargets Condition="'$(ImportVsSDKTargets)' == ''">true</ImportVsSDKTargets>
<!-- Path to VsSDK targets from the NuGet package -->
<VsSDKTargetsPath Condition="'$(VsSDKTargetsPath)' == '' and '$(VsSDKInstall)' != ''">$(VsSDKInstall)</VsSDKTargetsPath>
</PropertyGroup>
<!-- Import Microsoft.VsSDK.targets from VSSDK.BuildTools package -->
<Import Project="$(VsSDKTargetsPath)\Microsoft.VsSDK.targets"
Condition="'$(ImportVsSDKTargets)' == 'true' and '$(VsSDKTargetsPath)' != '' and Exists('$(VsSDKTargetsPath)\Microsoft.VsSDK.targets')" />
<!-- Fallback: Import from CustomAfterMicrosoftCSharpTargets if set -->
<Import Project="$(CustomAfterMicrosoftCSharpTargets)"
Condition="'$(ImportVsSDKTargets)' == 'true' and '$(CustomAfterMicrosoftCSharpTargets)' != '' and Exists('$(CustomAfterMicrosoftCSharpTargets)')" />
</Project>