예제 #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
    // Usage: <parentProcessId> <childProcessId> <engine>
    // Common engines:
    // - "{2E36F1D4-B23C-435D-AB41-18E608940038}" = .NET Core
    // - "{449EC4CC-30D2-4032-9256-EE18EB41B62B}" = .NET Framework
    static int Main(string[] args)
    {
        if (args.Length != 3)
        {
            return(1);
        }

        if (!int.TryParse(args[0], out var parentProcessId))
        {
            return(2);
        }

        if (!int.TryParse(args[1], out var childProcessId))
        {
            return(3);
        }

        var engine = args[2];

        var parentProcess = Process.GetProcessById(parentProcessId);

        if (parentProcess == null)
        {
            return(4);
        }

        var childProcess = Process.GetProcessById(childProcessId);

        if (childProcess == null)
        {
            return(5);
        }

        try
        {
            VisualStudioUtil.AttachDebugger(parentProcess, childProcess, engine);
        }
        catch
        {
            return(6);
        }

        return(0);
    }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }