public static DebuggingEngine[] GetDebuggingEnginesForSolution(string visualStudioSolutionPath)
        {
            var vsForSolution = InstanceFinder.GetVisualStudioInstanceForSolution(visualStudioSolutionPath);

            return(vsForSolution != null?GetDebuggingEnginesFromDte(vsForSolution) : new DebuggingEngine[]
            {
            });
        }
Exemple #2
0
        public static AttachResult AttachVisualStudioToProcess(Process visualStudioProcess, Process applicationProcess, bool customDebuggingEngines, params string[] engines)
        {
            _DTE visualStudioInstance;

            if (!InstanceFinder.TryGetVsInstance(visualStudioProcess.Id, out visualStudioInstance))
            {
                return(AttachResult.VisualStudioInstanceNotFound);
            }

            var availableEngines = DebuggingEngineDetector.GetEngines(visualStudioInstance).ToDictionary(e => e.Name);

            //Find the process you want the VS instance to attach to...
            var processToAttachTo = visualStudioInstance.Debugger.LocalProcesses.Cast <EnvDTE.Process>().FirstOrDefault(process => process.ProcessID == applicationProcess.Id);

            //Attach to the process.
            if (processToAttachTo == null)
            {
                return(AttachResult.TargetApplicatioNotFound);
            }

            if (customDebuggingEngines)
            {
                var selectedEngines = DebuggingEngineDetector.GetSelectedEngines(availableEngines, engines);
                if (selectedEngines.Length == 0)
                {
                    return(AttachResult.NoEngineSelected);
                }

                try
                {
                    var process3 = (EnvDTE90.Process3)processToAttachTo;
                    process3.Attach2(selectedEngines);
                }
                catch (COMException ex)
                {
                    return(ex.HResult == -1989083106 ? AttachResult.InvalidEngine : AttachResult.UnknownException);
                }
            }
            else
            {
                try
                {
                    processToAttachTo.Attach();
                }
                catch (COMException)
                {
                    return(AttachResult.UnknownException);
                }
            }

            ShowWindow((int)visualStudioProcess.MainWindowHandle, 3);
            SetForegroundWindow(visualStudioProcess.MainWindowHandle);

            return(AttachResult.NoError);
        }
Exemple #3
0
        public static DebuggingEngines LoadFromRunningVisualStudios()
        {
            var engines = new Dictionary <AvailableVisualStudioInstall, List <DebuggingEngine> >();

            foreach (var visualStudioProcess in InstanceFinder.GetVisualStudioProcesses())
            {
                var version = FileVersionInfo.GetVersionInfo(visualStudioProcess.MainModule.FileName);
                var install = new AvailableVisualStudioInstall(new Version(version.FileVersion), new FileInfo(visualStudioProcess.MainModule.FileName.ToLowerInvariant()));
                if (engines.ContainsKey(install))
                {
                    continue;
                }

                var enginesForInstance = DebuggingEngineDetector.GetAvailableEngines(visualStudioProcess, null);
                engines.Add(install, enginesForInstance.ToList());
            }

            return(new DebuggingEngines(engines));
        }
        public static DebuggingEngine[] GetDebuggingEnginesFromVisualStudioInstance(Process currentVisualStudioProcess)
        {
            _DTE dte;

            return(InstanceFinder.TryGetVsInstance(currentVisualStudioProcess.Id, out dte) ? GetDebuggingEnginesFromDte(dte) : new DebuggingEngine[] {});
        }