Skip to content

Commit

Permalink
Update Extension to SDK (MonoGame#8543)
Browse files Browse the repository at this point in the history
Fixes MonoGame#8530 

### Description of Change

- [x] Updated VS extension to SDK. (taken from Dean's Gist and tweaked)
- [x] Update CI to publish extension


Installing into all the VS2022 IDEs
<img width="329" alt="InstallIntoVS2022"
src="https://github.com/user-attachments/assets/0bb0a3a6-385b-4435-b8f9-49721e41b817">
  • Loading branch information
CartBlanche authored Nov 3, 2024
1 parent 8a21b20 commit 8b35cf5
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
MARKETPLACE_PAT: ${{ secrets.MARKETPLACE_PAT }}

- name: Make a Release
if: github.ref_type == 'tag'
Expand All @@ -158,7 +159,7 @@ jobs:
tag: ${{ github.ref_name }}
allowUpdates: true
removeArtifacts: true
artifacts: "nugets/*.nupkg"
artifacts: "nugets/*.nupkg;vsix/MonoGame.Templates.VSExtension.vsix"
token: ${{ secrets.GITHUB_TOKEN }}

tests:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
<PropertyGroup>
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{9EBC26EB-8412-4723-B715-1F5BCCECD77A}</ProjectGuid>
<TargetFramework>net472</TargetFramework>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MonoGame.Templates.VSExtension</RootNamespace>
<AssemblyName>MonoGame.Templates.VSExtension</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<RuntimeIdentifier>win</RuntimeIdentifier>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<UseCodebase>true</UseCodebase>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
Expand All @@ -27,28 +15,8 @@
<StartAction>Program</StartAction>
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Artifacts\MonoGame.Templates.VSExtension\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MonoGameTemplatesVSExtensionPackage.cs" />
</ItemGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
Expand All @@ -58,16 +26,21 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.10.*" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.10.*" />
<PackageReference Include="MessagePack" Version="2.5.187" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.11.40262" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.12.2069">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<Content Include="Templates.pkgdef">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="Exists('$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets')" />
<Target Name="PreCreateVsixContainer" BeforeTargets="GetVsixSourceItems">
<ItemGroup>
<_TemplatePackage Include="..\..\Artifacts\NuGet\MonoGame.Templates.CSharp.*.nupkg" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Templates.VSExtension", "MonoGame.Templates.VSExtension.csproj", "{78561F26-117A-4D42-B177-84374B768B45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{78561F26-117A-4D42-B177-84374B768B45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78561F26-117A-4D42-B177-84374B768B45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78561F26-117A-4D42-B177-84374B768B45}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{78561F26-117A-4D42-B177-84374B768B45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78561F26-117A-4D42-B177-84374B768B45}.Release|Any CPU.Build.0 = Release|Any CPU
{78561F26-117A-4D42-B177-84374B768B45}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BFA7EE0A-52F0-44FA-9D7E-CC05D906A0CF}
EndGlobalSection
EndGlobal

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Version="3.8.1.1" Id="MonoGame.Templates.VSExtension.03a6f6d5-6ec0-45ff-a4f6-ec098d51464d" Language="en-US" Publisher="MonoGame" />
<DisplayName>MonoGame Framework C# project templates</DisplayName>
<Description xml:space="preserve">This extension contains the C# project templates for using the MonoGame Framework</Description>
<Tags>.NET,C#,Game development,Templates,Games,Gamedev,Project,Mono,MonoGame</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="File" Path="Templates.pkgdef" />
</Assets>
<Metadata>
<Identity Version="3.8.2.0" Id="MonoGame.Templates.VSExtension.03a6f6d5-6ec0-45ff-a4f6-ec098d51464d" Language="en-US" Publisher="MonoGame" />
<DisplayName>MonoGame Framework C# project templates</DisplayName>
<Description xml:space="preserve">This extension contains the C# project templates for using the MonoGame Framework</Description>
<Tags>.NET,C#,Game development,Templates,Games,Gamedev,Project,Mono,MonoGame</Tags>
</Metadata>
<Installation>
<InstallationTarget Version="[17.0, 18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0, 18.0)" Id="Microsoft.VisualStudio.Pro">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0, 18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0, 18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0, 18.0)" Id="Microsoft.VisualStudio.Pro">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0, 18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.7.2,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="File" Path="Templates.pkgdef" />
<!-- This does not seem to work? -->
<Asset Type="Microsoft.VisualStudio.Icon" d:Source="File" Path="../../Images/Icon.png" />
<!--Need a decent preview image -->
<Asset Type="Microsoft.VisualStudio.PreviewImage" d:Source="File" Path="../../Images/Icon.png" />
</Assets>
</PackageManifest>
2 changes: 1 addition & 1 deletion build/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum ProjectType

public class BuildContext : FrostingContext
{
public static string VersionBase = "1.0.0";
public static string VersionBase = "3.8.2";
public static readonly Regex VersionRegex = new(@"^v\d+.\d+.\d+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly string DefaultRepositoryUrl = "https://github.com/MonoGame/MonoGame";

Expand Down
57 changes: 57 additions & 0 deletions build/DeployTasks/DeployVsixToMarketplaceTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

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

namespace BuildScripts;

[TaskName("DeployVsixToMarketplaceTask")]
[IsDependentOn(typeof(DownloadArtifactsTask))]
public sealed class DeployVsixToMarketplaceTask : FrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
if (context.BuildSystem().IsRunningOnGitHubActions)
{
var workflow = context.BuildSystem().GitHubActions.Environment.Workflow;
if (workflow.RefType == GitHubActionsRefType.Tag &&
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("MARKETPLACE_PAT")))
{
return true;
}
}

return false;
}

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

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

var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($":{pat}")));

using var fileStream = File.OpenRead(filePath);
using var content = new StreamContent(fileStream);
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

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

if (response.IsSuccessStatusCode)
{
context.Information("Successfully uploaded the VSIX to the Visual Studio Marketplace.");
}
else
{
context.Error($"Failed to upload VSIX. Response: {response.StatusCode} - {response.ReasonPhrase}");
}
}
}
3 changes: 3 additions & 0 deletions build/DeployTasks/DownloadArtifactsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ public override async Task RunAsync(BuildContext context)
context.CreateDirectory("nugets");
foreach (var os in new[] { "windows", "macos", "linux" })
await context.GitHubActions().Commands.DownloadArtifact($"nuget-{os}", "nugets");

context.CreateDirectory("vsix");
await context.GitHubActions().Commands.DownloadArtifact("MonoGame.Templates.VSExtension.vsix", "vsix");
}
}
6 changes: 6 additions & 0 deletions build/DeployTasks/UploadArtifactsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public override async Task RunAsync(BuildContext context)
await context.GitHubActions().Commands.UploadArtifact(new DirectoryPath(System.IO.Path.Combine(context.BuildOutput, "Tests", "Tools", "Release")), $"tests-tools-{os}");
await context.GitHubActions().Commands.UploadArtifact(new DirectoryPath(System.IO.Path.Combine(context.BuildOutput, "Tests", "DesktopGL", "Release")), $"tests-desktopgl-{os}");
if (context.IsRunningOnWindows())
{
await context.GitHubActions().Commands.UploadArtifact(new DirectoryPath(System.IO.Path.Combine(context.BuildOutput, "Tests", "WindowsDX", "Release")), $"tests-windowsdx-{os}");

// Assuming that the .vsix file has already been created and is located at this exact path.
var vsixFilePath = System.IO.Path.Combine(context.BuildOutput, "MonoGame.Templates.VSExtension", "net472", "MonoGame.Templates.VSExtension.vsix");
await context.GitHubActions().Commands.UploadArtifact(new FilePath(vsixFilePath), "MonoGame.Templates.VSExtension.vsix");
}
}
}
1 change: 1 addition & 0 deletions build/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public sealed class BuildAllTask : FrostingTask<BuildContext> { }
[TaskName("Deploy")]
[IsDependentOn(typeof(DeployNuGetsToGitHubTask))]
[IsDependentOn(typeof(DeployNuGetsToNuGetOrgTask))]
[IsDependentOn(typeof(DeployVsixToMarketplaceTask))]
public sealed class DeployTask : FrostingTask<BuildContext> { }

[TaskName("Test")]
Expand Down

0 comments on commit 8b35cf5

Please sign in to comment.