예제 #1
0
 public static Task AttachDebugger(Process process, bool debugMixedMode, IDiagnostics diagnostics)
 {
     return(diagnostics.RunAsync("Attaching Debugger", output =>
     {
         var dte = VisualStudioUtil.GetDteFromDebuggedProcess(Process.GetCurrentProcess());
         if (dte != null)
         {
             VisualStudioUtil.AttachDebugger(dte, process, debugMixedMode ? "Managed/Native" : "Managed");
         }
     }));
 }
예제 #2
0
        private static int StartProcess(string filename)
        {
            var executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);

            File.Copy(Process.GetCurrentProcess().MainModule.FileName, executablePath, true);
            using (var retryFilter = new RetryMessageFilter())
            {
                var dte     = VisualStudioUtil.GetDteFromDebuggedProcess(Process.GetCurrentProcess());
                var process = Process.Start(new ProcessStartInfo
                {
                    FileName        = executablePath,
                    Arguments       = Environment.CommandLine,
                    UseShellExecute = false,
                });
                if (dte != null)
                {
                    VisualStudioUtil.AttachDebugger(dte, process);
                }
                process.WaitForExit();
                FileUtil.TryDelete(executablePath);
                return(process.ExitCode);
            }
        }
예제 #3
0
        private int Run(string applicationPath, string rootSuffix, string[] args)
        {
            try
            {
                if (!ExtensionManagerUtil.IsValidProcessFileName(applicationPath, out var expectedFileName))
                {
                    return(StartProcess(expectedFileName));
                }

                var commands = new Dictionary <string, Func <int> >
                {
                    {
                        "Install", () =>
                        {
                            var extensionPaths = CommandLineParser.Many(args, "Install");
                            return(Installer.Install(applicationPath, rootSuffix, extensionPaths, allUsers: false));
                        }
                    },
                    {
                        "InstallAndStart", () =>
                        {
                            var extensionPaths = CommandLineParser.Many(args, "InstallAndStart");
                            var result         = Installer.Install(applicationPath, rootSuffix, extensionPaths, allUsers: false);
                            using (var retryFilter = new RetryMessageFilter())
                            {
                                var dte     = VisualStudioUtil.GetDteFromDebuggedProcess(Process.GetCurrentProcess());
                                var process = Process.Start(applicationPath, $"/RootSuffix {rootSuffix}");
                                if (dte != null)
                                {
                                    VisualStudioUtil.AttachDebugger(dte, process);
                                }
                                return(result);
                            }
                        }
                    },
                    {
                        "Uninstall", () =>
                        {
                            var extensionIds = CommandLineParser.Many(args, "Uninstall");
                            return(Installer.Uninstall(applicationPath, rootSuffix, extensionIds, skipGlobal: false));
                        }
                    },
                    {
                        "IsProfileInitialized", () =>
                        {
                            using (var externalSettingsManager = ExternalSettingsManager.CreateForApplication(applicationPath, rootSuffix))
                            {
                                var settings             = externalSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
                                var isProfileInitialized = settings.CollectionExists("Profile") && settings.GetPropertyNames("Profile").Contains("LastResetSettingsFile");
                                return(Convert.ToInt32(isProfileInitialized));
                            }
                        }
                    },
                };

                foreach (var cmd in commands)
                {
                    if (CommandLineParser.Contains(args, cmd.Key))
                    {
                        return(cmd.Value());
                    }
                }

                throw new Exception($@"Invalid command");
            }
            catch (Exception e)
            {
                Console.Error.Write(e.ToString());
                return(-1);
            }
        }