예제 #1
0
 static void Install(string vsExe, IInstallableExtension vsix, string rootSuffix)
 {
     using (var esm = ExternalSettingsManager.CreateForApplication(vsExe, rootSuffix))
     {
         var ems       = new ExtensionManagerService(esm);
         var installed = ems.GetInstalledExtensions().FirstOrDefault(x => x.Header.Identifier == vsix.Header.Identifier);
         if (installed != null)
         {
             ems.Uninstall(installed);
         }
         ems.Install(vsix, perMachine: false);
     }
 }
예제 #2
0
        static void UninstallAll(ExtensionManagerService service)
        {
            // We only want extensions which are not installed per machine and we want them sorted by their dependencies.
            var installedExtensions = service.GetInstalledExtensions()
                                      .Where((installedExtension) => !installedExtension.InstalledPerMachine)
                                      .OrderBy((installedExtension) => installedExtension,
                                               Comparer <IInstalledExtension> .Create((left, right) =>
            {
                if (left.References.Count() == 0)
                {
                    // When left.References.Count() is zero, then we have two scenarios:
                    //    * right.References.Count() is zero, and the order of the two components doesn't matter, so we return 0
                    //    * right.References.Count() is not zero, which means it should be uninstalled after left, so we return -1
                    return(right.References.Count() == 0 ? 0 : -1);
                }
                else if (right.References.Count() == 0)
                {
                    // When left.References.Count() is not zero, but right.References.Count() is, then we have one scenario:
                    //    * right should be uninstalled before left, so we return 1
                    return(1);
                }

                if (left.References.Any((extensionReference) => extensionReference.Identifier == right.Header.Identifier))
                {
                    // When left.References contains right, then we have one scenario:
                    //    * left is dependent on right, which means it must be uninstalled afterwards, so we return 1
                    return(1);
                }
                else if (right.References.Any((extensionReference) => extensionReference.Identifier == left.Header.Identifier))
                {
                    // When right.References contains left, then we have one scenario:
                    //    * right is dependent on left, which means it must be uninstalled afterwards, so we return -1
                    return(-1);
                }

                // Finally, if both projects contain references, but neither depends on the other, we have one scenario:
                //    * left and right are independent of each other, and the order of the two components doesn't matter, so we return 0
                return(0);
            }));

            foreach (var installedExtension in installedExtensions)
            {
                Console.WriteLine("  Uninstalling {0}... ", installedExtension.Header.Name);
                service.Uninstall(installedExtension);
            }
        }
 static void Install(string vsExe, IInstallableExtension vsix, string rootSuffix)
 {
     using (var esm = ExternalSettingsManager.CreateForApplication(vsExe, rootSuffix))
     {
         var ems = new ExtensionManagerService(esm);
         var installed = ems.GetInstalledExtensions().FirstOrDefault(x => x.Header.Identifier == vsix.Header.Identifier);
         if (installed != null)
             ems.Uninstall(installed);
         ems.Install(vsix, perMachine: false);
     }
 }