Exemplo n.º 1
0
        internal static void Main(string[] args)
        {
            var consoleContext = new ConsoleContext(Console.Out);
            var commandLine    = ParseCommandLine(consoleContext, args);

            if (commandLine.ToolAction == ToolAction.Help)
            {
                PrintHelp(consoleContext);
                Environment.Exit(1);
                return;
            }

            var installedVersions = InstalledVersionUtilities.GetInstalledVersions().Where(iv => Filter(iv, commandLine));

            foreach (var installedVersion in installedVersions)
            {
                // HACK: We mustn't create an app domain when installing for VS2017.
                // https://github.com/jaredpar/VsixUtil/pull/8
                var createDomain = !commandLine.DefaultDomain;
                if (createDomain && installedVersion.VsVersion == VsVersion.Vs2017)
                {
                    ExecuteOutOfProc(consoleContext, installedVersion.ApplicationPath, commandLine.ToolAction, commandLine.Arg);
                    continue;
                }

                using (var applicationContext = new ApplicationContext(installedVersion, createDomain))
                {
                    var factory       = applicationContext.CreateInstance <CommandRunnerFactory>();
                    var commandRunner = factory.Create(consoleContext, installedVersion, commandLine.RootSuffix);
                    commandRunner.Run(commandLine.ToolAction, commandLine.Arg);
                }
            }
        }
Exemplo n.º 2
0
        private static void ExecuteOutOfProc(ConsoleContext consoleContext, string applicationPath, ToolAction toolAction, string arg)
        {
            var exeFile   = Assembly.GetEntryAssembly().Location;
            var arguments = "/defaultDomain /product \"" + applicationPath + "\" /" + toolAction + " \"" + arg + "\"";
            var startInfo = new ProcessStartInfo(exeFile, arguments)
            {
                RedirectStandardOutput = true, CreateNoWindow = true, UseShellExecute = false
            };
            var process = Process.Start(startInfo);
            var output  = process.StandardOutput.ReadToEnd();

            consoleContext.Write(output);
            process.WaitForExit();
        }