Exemplo n.º 1
0
        public void InstallExtension(string vsixPath)
        {
            if (!Exists())
            {
                throw new InvalidOperationException("Cannot install VSIX in non-existing instance.");
            }

            using (var settings = ExternalSettingsManager.CreateForApplication(GetExePath(), Suffix))
            {
                var ems = new ExtensionManagerService(settings);
                IInstallableExtension vsix = ExtensionManagerService.CreateInstallableExtension(vsixPath);

                if (ems.IsInstalled(vsix))
                {
                    IInstalledExtension installedVsix = ems.GetInstalledExtension(vsix.Header.Identifier);
                    ems.Uninstall(installedVsix);
                    if (ems.IsInstalled(vsix))
                    {
                        throw new InvalidOperationException("Could not uninstall already installed GoogleTestAdapter.");
                    }
                }

                ems.Install(vsix, perMachine: false);
                if (!ems.IsInstalled(vsix))
                {
                    throw new InvalidOperationException("Could not install GoogleTestAdapter.");
                }

                ems.Close();
            }
        }
        internal void InstallExtension(string vsixPath)
        {
            if (!Exists())
                throw new InvalidOperationException("Cannot install VSIX in non-existing instance.");

            using (var settings = ExternalSettingsManager.CreateForApplication(GetExePath(), Suffix))
            {
                var ems = new ExtensionManagerService(settings);
                IInstallableExtension vsix = ExtensionManagerService.CreateInstallableExtension(vsixPath);

                if (ems.IsInstalled(vsix))
                {
                    IInstalledExtension installedVsix = ems.GetInstalledExtension(vsix.Header.Identifier);
                    ems.Uninstall(installedVsix);
                    if (ems.IsInstalled(vsix))
                        throw new InvalidOperationException("Could not uninstall already installed GoogleTestAdapter.");
                }

                ems.Install(vsix, perMachine: false);
                if (!ems.IsInstalled(vsix))
                    throw new InvalidOperationException("Could not install GoogleTestAdapter.");

                ems.Close();
            }
        }
Exemplo n.º 3
0
        private static IInstalledExtension PerformInstallation(IInstallableExtension vsix, string devenvPath, string hive)
        {
            IInstalledExtension extension;

            using (var settingsManager = ExternalSettingsManager.CreateForApplication(devenvPath, hive))
            {
                var identifier = vsix.Header.Identifier;
                var name       = vsix.Header.Name;

                Log($"Preparing to install '{name}' with identifier '{identifier}' into '{hive}'");

                var extensionManager = new ExtensionManagerService(settingsManager);

                if (extensionManager.TryGetInstalledExtension(identifier, out extension))
                {
                    Log($"Extension '{name}' was already installed. Uninstalling...");
                    try
                    {
                        extensionManager.Uninstall(extension);
                        extensionManager.CommitExternalUninstall(extension);
                    }
                    catch (Exception ex)
                    {
                        LogError($"An error ocurred while trying to uninstall '{name}'. Rolling back...", ex);
                        RevertUninstall(extensionManager, extension);
                        throw;
                    }
                }
                try
                {
                    Log($"Starting installation of '{name}'");
                    extensionManager.Install(vsix, perMachine: false);
                    extension = extensionManager.GetInstalledExtension(identifier);
                    Log($"Installation of '{name}' into '{hive}' completed successfully.");
                }
                catch (Exception ex)
                {
                    LogError($"An error ocurred while trying to install '{name}'. Rolling back...", ex);
                    RevertUninstall(extensionManager, extension);
                    throw;
                }
            }

            return(extension);
        }