|
| 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>"$(VsixPublisher)" publish -personalAccessToken "$(PersonalAccessToken)" -payload "$(PublishExtension)" -publishManifest "$(PublishManifest)"</PublishCommand> |
| 64 | + <PublishCommand Condition="'$(PublishIgnoreWarnings)' != ''">$(PublishCommand) -ignoreWarnings "$(PublishIgnoreWarnings)"</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