Skip to content

Changes to use VsixPublisher.exe to auto-publish the extension. #8835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 63 additions & 15 deletions build/DeployTasks/DeployVsixToMarketplaceTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

namespace BuildScripts;

Expand All @@ -10,6 +11,9 @@ public sealed class DeployVsixToMarketplaceTask : FrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
#if DEBUG
return true;
#else
if (context.BuildSystem().IsRunningOnGitHubActions)
{
var workflow = context.BuildSystem().GitHubActions.Environment.Workflow;
Expand All @@ -21,37 +25,81 @@ public override bool ShouldRun(BuildContext context)
}

return false;
#endif
}

public override async void Run(BuildContext context)
public override void Run(BuildContext context)
{
var pat = context.EnvironmentVariable("MARKETPLACE_PAT");
var publisher = "MonoGame";
var extensionName = "MonoGame.Templates.VSExtension";
var vsixPath = "vsix/MonoGame.Templates.VSExtension.vsix";

var filePath = "vsix/MonoGame.Templates.VSExtension.vsix";
if (!File.Exists(filePath))
if (!File.Exists(vsixPath))
{
context.Error("VSIX file not found!");
return;
}

var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($":{pat}")));
// Find VsixPublisher.exe location - adjust as needed for your environment
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string vsixPublisherPath = string.Empty;

using var fileStream = File.OpenRead(filePath);
using var content = new StreamContent(fileStream);
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
context.Log.Information("Looking for VsixPublisher in VS Edition locations...");
// Try to find it in other edition folders
foreach (var edition in new[] { "Enterprise", "Professional", "Community" })
{
var vsEditionPath = System.IO.Path.Combine(
programFiles,
"Microsoft Visual Studio",
"2022",
edition,
"VSSDK",
"VisualStudioIntegration",
"Tools",
"Bin",
"VsixPublisher.exe");

var response = await client.PutAsync($"https://marketplace.visualstudio.com/_apis/gallery/publishers/{publisher}/vsextensions/{extensionName}/versions", content);
if (File.Exists(vsEditionPath))
{
vsixPublisherPath = vsEditionPath;
break;
}
}

if (response.IsSuccessStatusCode)
if (!File.Exists(vsixPublisherPath))
{
context.Information("Successfully uploaded the VSIX to the Visual Studio Marketplace.");
context.Error("VsixPublisher.exe not found!");
return;
}
else

var manifestPath = "vsix/publishManifest.json";

if (!File.Exists(manifestPath))
{
context.Error("publishManifest.json not found!");
return;
}

// Run VsixPublisher
var processSettings = new ProcessSettings
{
context.Error($"Failed to upload VSIX. Response: {response.StatusCode} - {response.ReasonPhrase}");
Arguments = $"publish -payload \"{vsixPath}\" -publishManifest \"{manifestPath}\" -personalAccessToken \"{pat}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
Silent = false
};

context.Information($"Publishing VSIX using VsixPublisher at: {vsixPublisherPath} with arguments: {processSettings.Arguments}");

/*TODO uncomment this block when above it working
var exitCode = context.StartProcess(vsixPublisherPath, processSettings, out var stdOutput, out var stdError);

if (exitCode == 0)
{
context.Information($"Successfully uploaded the VSIX to the Visual Studio Marketplace.{Environment.NewLine}Info: {stdOutput}");
}
else
{
context.Error($"Failed to upload VSIX. Exit code: {exitCode}{Environment.NewLine}Error:{stdError}");
}*/
}
}
13 changes: 13 additions & 0 deletions vsix/publishManifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/vsix-publish",
"categories": [ "templates" ], // The categories of the extension. Between 1 and 3 categories are required.
"identity": {
"internalName": "MonoGame.Templates.VSExtension" // If not specified, we try to generate the name from the display name of the extension in the vsixmanifest file.
// Required if the display name is not the actual name of the extension.
},
"overview": "overview.md", // Path to the "readme" file that gets uploaded to the Marketplace. Required.
"priceCategory": "free", // Either "free", "trial", or "paid". Defaults to "free".
"publisher": "MonoGame Foundation", // The name of the publisher. Required.
"private": false, // Specifies whether or not the extension should be public when uploaded. Defaults to false.
"qna": true // Specifies whether or not the extension should have a Q&A section. Defaults to true.
}
Loading