コード例 #1
0
ファイル: Maestro.cs プロジェクト: vbfox/AttachR
        public RunResult Run(string visualStudioSolutionPath, IEnumerable <DebuggingTargetViewModel> debuggingTargets, bool debug, bool runUnselected)
        {
            var     targets = debuggingTargets.ToList();
            var     requiresVisualStudio = debug && targets.SelectMany(t => t.DebuggingEngines).Any();
            Process visualStudioProcess  = null;

            if (requiresVisualStudio)
            {
                try
                {
                    visualStudioProcess = Retrier.RunWithRetryOnException(() => InstanceFinder.GetVisualStudioProcessForSolution(visualStudioSolutionPath));
                }
                catch (AggregateException ex)
                {
                    return(new RunResult
                    {
                        Message = $"Errors while looking for VS.NET instances {visualStudioSolutionPath}. Errors : {string.Join(". ", ex.InnerExceptions.Select(e => e.Message).ToArray())}"
                    });
                }

                if (visualStudioProcess == null)
                {
                    return(new RunResult
                    {
                        Message = $"No visual studio instance found with solution {visualStudioSolutionPath}"
                    });
                }
            }

            foreach (var target in targets.Where(tr => (runUnselected || tr.Selected) && tr.CurrentProcess == null))
            {
                RunResult run;
                if (!RunSingleTarget(debug, target, visualStudioProcess, out run))
                {
                    return(run);
                }
            }

            return(new RunResult());
        }
コード例 #2
0
ファイル: Maestro.cs プロジェクト: vbfox/AttachR
        private bool RunSingleTarget(bool debug, DebuggingTargetViewModel target, Process visualStudioProcess, out RunResult run)
        {
            var psi = new ProcessStartInfo(target.Executable, target.CommandLineArguments)
            {
                WorkingDirectory = target.WorkingDirectory
            };
            var process     = Process.Start(psi);
            var localTarget = target;

            if (process != null && debug)
            {
                process.Exited += (_, __) => localTarget.CurrentProcess = null;

                try
                {
                    var engineModes = localTarget.DebuggingEngines.Where(x => x.Selected).Select(x => x.Name).ToArray();
                    localTarget.LastError = "";
                    var result = Retrier.RunWithRetryOnException(() => Attacher.AttachVisualStudioToProcess(visualStudioProcess, process, target.UseCustomDebuggingEngines, engineModes));
                    localTarget.LastError = GetError(result);
                }
                catch (AggregateException ex)
                {
                    localTarget.LastError = ex.Message;

                    {
                        run = new RunResult
                        {
                            Message =
                                $"Errors while attaching process {target.Executable} to VS.NET. Errors : {string.Join(". ", ex.InnerExceptions.Select(e => e.Message).ToArray())}"
                        };
                        return(false);
                    }
                }
            }

            target.CurrentProcess = process;
            run = new RunResult();
            return(true);
        }