Skip to content

Commit 249c909

Browse files
committed
Created an MSBuild target to publish an extension to the marketplace.
1 parent e124ffe commit 249c909

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

Community.VisualStudio.Toolkit.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "imports", "imports", "{544D
7676
src\toolkit\nuget\build\imports\ExtensibilityEssentialsCheck.targets = src\toolkit\nuget\build\imports\ExtensibilityEssentialsCheck.targets
7777
src\toolkit\nuget\build\imports\MSBuildCapabilities.props = src\toolkit\nuget\build\imports\MSBuildCapabilities.props
7878
src\toolkit\nuget\build\imports\NewtonsoftJsonVersionCheck.targets = src\toolkit\nuget\build\imports\NewtonsoftJsonVersionCheck.targets
79+
src\toolkit\nuget\build\imports\PublishToMarketplace.targets = src\toolkit\nuget\build\imports\PublishToMarketplace.targets
7980
EndProjectSection
8081
EndProject
8182
Global

src/toolkit/nuget/build/Community.VisualStudio.Toolkit.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
<Import Project="$(MSBuildThisFileDirectory)imports\ExtensibilityEssentialsCheck.targets"/>
44
<Import Project="$(MSBuildThisFileDirectory)imports\NewtonsoftJsonVersionCheck.targets"/>
5+
<Import Project="$(MSBuildThisFileDirectory)imports\PublishToMarketplace.targets"/>
56

67
</Project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<Project>
2+
3+
<ItemGroup>
4+
<!--
5+
Update the build tools NuGet package reference to generate a path property. This will
6+
cause MSBuild to create a property called `PkgMicrosoft_VSSDK_BuildTools` that defines
7+
the location of the NuGet package. We will use that to find the VsixPublisher executable.
8+
-->
9+
<PackageReference Update="Microsoft.VSSDK.BuildTools">
10+
<GeneratePathProperty>true</GeneratePathProperty>
11+
</PackageReference>
12+
</ItemGroup>
13+
14+
<Target Name="PublishToMarketplace" DependsOnTargets="Rebuild">
15+
<Message Text="Publishing extension to the marketplace..." Importance="normal"/>
16+
17+
<!-- Before anything else happens, ensure that only "Release" builds can be published. -->
18+
<Error
19+
Condition="'$(Configuration)' != 'Release'"
20+
Text="The configuration must be 'Release' when publishing to the marketplace."
21+
/>
22+
23+
<PropertyGroup>
24+
<!--
25+
Find the VsixPublisher executable if it has not been specified. This uses the property that was
26+
generated by setting the `GeneratePathProperty` property to true for the build tools NuGet package.
27+
-->
28+
<VsixPublisher Condition="'$(VsixPublisher)' == ''">$(PkgMicrosoft_VSSDK_BuildTools)\tools\vssdk\bin\VsixPublisher.exe</VsixPublisher>
29+
30+
<!--
31+
If a manifest file name has not been specified, then search for it by starting from the
32+
project directory and looking up. Although the function is called `GetPathOfFileAbove`,
33+
it actually starts looking in the specified directory (the second parameter), so the
34+
manifest file can be placed alongside the the project file and it will be found.
35+
-->
36+
<PublishManifest Condition="'$(PublishManifest)' == ''">$([MSBuild]::GetPathOfFileAbove('publish.json', '$(ProjectDir)'))</PublishManifest>
37+
38+
<!-- Build the path to the extension file if it hasn't been specified. -->
39+
<PublishExtension Condition="'$(PublishExtensionFileName)' == ''">$(ProjectDir)$(TargetVsixContainer)</PublishExtension>
40+
</PropertyGroup>
41+
42+
<!-- Log some properties to assist with debugging. -->
43+
<Message Text="BuildTools: $(PkgMicrosoft_VSSDK_BuildTools)" Importance="$(PublishLogLevel)" />
44+
<Message Text="VsixPublisher: $(VsixPublisher)" Importance="$(PublishLogLevel)" />
45+
<Message Text="Manifest: $(PublishManifest)" Importance="$(PublishLogLevel)" />
46+
<Message Text="Extension: $(PublishExtension)" Importance="$(PublishLogLevel)" />
47+
<Message Text="Ignore Warnings: $(PublishIgnoreWarnings)" Importance="$(PublishLogLevel)" />
48+
49+
<!-- Verify that the manifest file was found. -->
50+
<Error
51+
Condition="'$(PublishManifest)' == '' or !Exists('$(PublishManifest)')"
52+
Text="The 'publish manifest' file was not found. Either specify the 'PublishManifest' build property, or create a 'publish.json' file in the same directory as the project file or solution file. For more information about the 'publish manifest' file, visit https://docs.microsoft.com/visualstudio/extensibility/walkthrough-publishing-a-visual-studio-extension-via-command-line#publishmanifest-file"
53+
/>
54+
55+
<!-- A personal access token needs to be specified. -->
56+
<Error
57+
Condition="'$(PersonalAccessToken)' == ''"
58+
Text="A personal access token must be specified in the 'PersonalAccessToken' build property."
59+
/>
60+
61+
<!-- Everything should be valid now, so define the command to publish the extension. -->
62+
<PropertyGroup>
63+
<PublishCommand>&quot;$(VsixPublisher)&quot; publish -personalAccessToken &quot;$(PersonalAccessToken)&quot; -payload &quot;$(PublishExtension)&quot; -publishManifest &quot;$(PublishManifest)&quot;</PublishCommand>
64+
<PublishCommand Condition="'$(PublishIgnoreWarnings)' != ''">$(PublishCommand) -ignoreWarnings &quot;$(PublishIgnoreWarnings)&quot;</PublishCommand>
65+
</PropertyGroup>
66+
67+
<Exec
68+
Command="$(PublishCommand)"
69+
StandardOutputImportance="normal"
70+
StandardErrorImportance="high"
71+
LogStandardErrorAsError="true"
72+
IgnoreExitCode="true"
73+
>
74+
<Output TaskParameter="ExitCode" PropertyName="PublishExitCode"/>
75+
</Exec>
76+
77+
<Message Condition="'$(PublishExitCode)' == '0'" Text="Extension published successfully." Importance="normal"/>
78+
<Error Condition="'$(PublishExitCode)' != '0'" Text="Failed to publish the extension."/>
79+
</Target>
80+
81+
</Project>

0 commit comments

Comments
 (0)