From 40a59d5c09780e282b378dff6723d4fe8ae86176 Mon Sep 17 00:00:00 2001 From: Iakov Lilo Date: Fri, 7 Feb 2025 14:23:32 +1100 Subject: [PATCH] Change the ID of the extension and add notification if 2 extensions are installed --- src/OpenSilver.VSIX/OpenSilver.VSIX.csproj | 11 ++- src/OpenSilver.VSIX/OpenSilverPackage.cs | 72 +++++++++++++++++++ .../source.extension.vsixmanifest | 5 +- 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/OpenSilver.VSIX/OpenSilverPackage.cs diff --git a/src/OpenSilver.VSIX/OpenSilver.VSIX.csproj b/src/OpenSilver.VSIX/OpenSilver.VSIX.csproj index 5f9e4f1..c473ca0 100644 --- a/src/OpenSilver.VSIX/OpenSilver.VSIX.csproj +++ b/src/OpenSilver.VSIX/OpenSilver.VSIX.csproj @@ -4,6 +4,7 @@ 16.0 bin\OpenSilver\$(Configuration)\ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + true AnyCPU @@ -35,17 +36,18 @@ OpenSilver.VSIX OpenSilver v4.7.2 - false - false + true + true false false - false + true false Program $(DevEnvDir)devenv.exe /rootsuffix Exp + @@ -234,6 +236,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + 11.0.0 + diff --git a/src/OpenSilver.VSIX/OpenSilverPackage.cs b/src/OpenSilver.VSIX/OpenSilverPackage.cs new file mode 100644 index 0000000..a9d112a --- /dev/null +++ b/src/OpenSilver.VSIX/OpenSilverPackage.cs @@ -0,0 +1,72 @@ +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Threading; +using Microsoft.VisualStudio.ExtensionManager; +using System; +using System.Threading; +using System.Threading.Tasks; +using System.Diagnostics; + +namespace OpenSilver.VSIX +{ + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] + [InstalledProductRegistration("OpenSilver SDK", "OpenSilver SDK for Visual Studio", "3.0")] + [ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)] + public sealed class OpenSilverPackage : AsyncPackage + { + private const string OldExtensionId = "OpenSilver.64201874-6ead-4828-b5af-31a76285b73d"; + + protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) + { + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + + DetectOldExtension(); + } + + private void DetectOldExtension() + { + ThreadHelper.ThrowIfNotOnUIThread(); + + try + { + IVsExtensionManager extensionManager = (IVsExtensionManager)GetService(typeof(SVsExtensionManager)); + if (extensionManager != null) + { + foreach (var extension in extensionManager.GetInstalledExtensions()) + { + if (string.Equals(extension.Header.Identifier, OldExtensionId, StringComparison.OrdinalIgnoreCase)) + { + int result = VsShellUtilities.ShowMessageBox( + this, + "An older version of the OpenSilver extension is installed. Please uninstall the old version to avoid conflicts.\n\n" + + "Would you like to open a page with detailed instructions on how to proceed?", + "Extension Conflict Detected", + OLEMSGICON.OLEMSGICON_WARNING, + OLEMSGBUTTON.OLEMSGBUTTON_YESNO, + OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + + if (result == (int)Microsoft.VisualStudio.VSConstants.MessageBoxResult.IDYES) + { + Process.Start(new ProcessStartInfo("https://opensilver.net/uninstall-old-extension") + { + UseShellExecute = true + }); + } + break; + } + } + } + } + catch (Exception ex) + { + VsShellUtilities.ShowMessageBox( + this, + "An error occurred while checking for old extensions: " + ex.Message, + "Error", + OLEMSGICON.OLEMSGICON_CRITICAL, + OLEMSGBUTTON.OLEMSGBUTTON_OK, + OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + } + } + } +} diff --git a/src/OpenSilver.VSIX/source.extension.vsixmanifest b/src/OpenSilver.VSIX/source.extension.vsixmanifest index 783e616..cc813da 100644 --- a/src/OpenSilver.VSIX/source.extension.vsixmanifest +++ b/src/OpenSilver.VSIX/source.extension.vsixmanifest @@ -1,8 +1,8 @@ - - OpenSilver + + OpenSilver SDK Project templates and XAML Designer for creating OpenSilver applications. OpenSilver is an open-source reimplementation of Silverlight that runs on current browsers via WebAssembly. Logo_32x32.png Logo_200x200.png @@ -65,5 +65,6 @@ +