Example #1
0
        public override bool Execute()
        {
            try
            {
                if (!File.Exists(VsixPath))
                {
                    throw new Exception("Cannot find VSIX file " + VsixPath);
                }

                var visualStudios = GetAllVisualStudios();
                if (visualStudios.Length == 0)
                {
                    throw new Exception("Cannot find any installed copies of Visual Studio.");
                }

                var vsix = ExtensionManagerService.CreateInstallableExtension(VsixPath);

                foreach (var vs in visualStudios)
                {
                    Console.WriteLine("Installing {0} version {1} to Visual Studio {2} /RootSuffix {3}",
                                      vsix.Header.Name, vsix.Header.Version, vs.Version, RootSuffix);

                    Install(vs.ExePath, vsix, RootSuffix);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                return(false);
            }
        }
Example #2
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();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Log("Starting HostProcess...");

            if (args.Length < 2)
            {
                LogError($"Invalid number of arguments. Expected 3 but was {args.Length}: {string.Join(", ", args)}");
                Environment.Exit(-1);
            }

            string vsixPath   = args[0];
            string devenvPath = args[1];
            string hive       = args.Length == 3 ? args[2] : null;

            try
            {
                IInstallableExtension vsix = ExtensionManagerService.CreateInstallableExtension(vsixPath);

                if (string.IsNullOrWhiteSpace(hive))
                {
                    hive = "";
                }

                PerformInstallation(vsix, devenvPath, hive);
            }
            catch (Exception)
            {
                Environment.Exit(-1);
            }

            Log("Exiting HostProcess...");
        }
        static int Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                PrintUsage();
                return(1);
            }

            string version;

            if (args.Length == 3)
            {
                version = args[0];
                args    = args.Skip(1).ToArray();
            }
            else
            {
                version = FindVsVersions().LastOrDefault().ToString();
                if (string.IsNullOrEmpty(version))
                {
                    return(PrintError("Cannot find any installed copies of Visual Studio."));
                }
            }

            string vsExe = GetVersionExe(version);

            if (string.IsNullOrEmpty(vsExe) && version.All(char.IsNumber))
            {
                version += ".0";
                vsExe    = GetVersionExe(version);
            }

            if (string.IsNullOrEmpty(vsExe))
            {
                Console.Error.WriteLine("Cannot find Visual Studio " + version);
                PrintVsVersions();
                return(1);
            }

            if (!File.Exists(args[1]))
            {
                return(PrintError("Cannot find VSIX file " + args[1]));
            }

            var vsix = ExtensionManagerService.CreateInstallableExtension(args[1]);

            Console.WriteLine("Installing " + vsix.Header.Name + " version " + vsix.Header.Version + " to Visual Studio " + version + " /RootSuffix " + args[0]);

            try
            {
                Install(vsExe, vsix, args[0]);
            }
            catch (Exception ex)
            {
                return(PrintError("Error: " + ex.Message));
            }

            return(0);
        }
        protected override ContextMenuStrip CreateMenu()
        {
            var menuStrip = new ContextMenuStrip();
            var item      = new ToolStripMenuItem("Copy VSIX ID to Clipboard");

            item.Click += (sender, args) =>
            {
                string path = SelectedItemPaths.FirstOrDefault();
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                IInstallableExtension vsix = ExtensionManagerService.CreateInstallableExtension(path);

                Clipboard.SetText(vsix.Header.Identifier);
            };

            menuStrip.Items.Add(item);
            return(menuStrip);
        }
Example #6
0
        protected override bool CanShowMenu()
        {
            var paths = SelectedItemPaths.ToArray();

            if (paths.Length != 1 ||
                Path.GetExtension(paths[0]).ToLowerInvariant() != ".vsix")
            {
                return(false);
            }

            try
            {
                vsix = ExtensionManagerService.CreateInstallableExtension(paths[0]);
            }
            catch (Exception ex)
            {
                LogError($"Unable to load the extension '{paths[0]}'", ex);
                return(false);
            }

            return(vsix != null);
        }
Example #7
0
        static int Main(string[] args)
        {
            var app = new CommandLineApplication {
                Name = "vsix"
            };

            app.HelpOption("-?|-h|--help");

            var vsixPath = app.Option(
                "-f|--vsix",
                "The path to the vsix to install",
                CommandOptionType.SingleValue);
            var version = app.Option(
                "-v|--version",
                "The version of VS to install to.",
                CommandOptionType.SingleValue);
            var suffix = app.Option(
                "-s|--suffix",
                "The Visual Studio root suffix to use.",
                CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                if (!vsixPath.HasValue())
                {
                    Console.Error.WriteLine("Need to specify the --vsix parameter.");
                    return(1);
                }
                if (!File.Exists(vsixPath.Value()))
                {
                    Console.Error.Write($"Cannot find the vsix at {vsixPath.Value()}");
                    return(1);
                }

                var versionValue = version.HasValue() ? version.Value() : "14.0";
                var vsExe        = GetVersionExe(versionValue);
                if (string.IsNullOrEmpty(vsExe))
                {
                    Console.Error.WriteLine("Cannot find Visual Studio " + version);
                    return(1);
                }

                var suffixValue = suffix.HasValue() ? suffix.Value() : "exp";

                var vsixPackage = ExtensionManagerService.CreateInstallableExtension(vsixPath.Value());
                Console.Error.WriteLine($"Installing {vsixPackage.Header.Name} version {vsixPackage.Header.Version}");

                try
                {
                    Install(vsExe, vsixPackage, suffixValue);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"Failed to install extension: {ex.Message}");
                    return(1);
                }

                return(0);
            });

            return(app.Execute(args));
        }