public async Task GetDebuggingPropertiesAsync()

in VisualStudioAdapter/VisualStudio.cs [63:144]


        public async Task<DebuggingProperties> GetDebuggingPropertiesAsync(string binary)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var vsSolution = (IVsSolution)this._serviceProvider.GetService(typeof(SVsSolution));
            if (vsSolution == null)
            {
                return null;
            }

            IEnumHierarchies enumHierarchies;
            Guid guid = Guid.Empty;
            var hr = vsSolution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref guid, out enumHierarchies);
            if (hr != VSConstants.S_OK || enumHierarchies == null)
            {
                return null;
            }

            List<IVsHierarchy> deferredHierarchies = new List<IVsHierarchy>();

            IVsHierarchy[] hierarchies = new IVsHierarchy[1];
            uint fetched;
            while (enumHierarchies.Next(1, hierarchies, out fetched) == VSConstants.S_OK && fetched > 0)
            {
                var hierarchy = hierarchies[0];
                if (hierarchy == null)
                {
                    continue;
                }

                if (IsInDeferredState(hierarchy))
                {
                    deferredHierarchies.Add(hierarchy);
                }
                else
                {
                    var debuggingProperties = GetDebugPropsIfMatching(hierarchy, binary);
                    if (debuggingProperties != null)
                    {
                        return debuggingProperties;
                    }
                }
            }

            // If binary was not found in loaded hierarchies, fall back to searching in deferred hierarchies.
            if (deferredHierarchies.Count > 0)
            {
                var workspaceService = (IVsSolutionWorkspaceService)this._serviceProvider.GetService(typeof(SVsSolutionWorkspaceService));
                var indexService = workspaceService.CurrentWorkspace.GetIndexWorkspaceService();
                var solutionService = workspaceService.CurrentWorkspace.GetService<ISolutionService>();

                var solutionPath = workspaceService.SolutionFile;
                var solutionConfig = (SolutionConfiguration2)this._dte.Solution.SolutionBuild.ActiveConfiguration;
                var solutionDir = Path.GetDirectoryName(solutionPath);
                var solutionContext = $"{solutionConfig.Name}|{solutionConfig.PlatformName}";

                foreach (var hierarchy in deferredHierarchies)
                {
                    var projectPath = GetProjectPath(hierarchy);
                    if (projectPath == null)
                    {
                        continue;
                    }

                    var isMatch = await ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                    {
                        var projectContext = await solutionService.GetProjectConfigurationAsync(solutionPath, projectPath, solutionContext);
                        var outputs = await indexService.GetFileReferencesAsync(projectPath, refreshOption: true, context: projectContext,
                            referenceTypes: (int)FileReferenceInfoType.Output);
                        return outputs.Select(f => workspaceService.CurrentWorkspace.MakeRooted(f.Path)).Contains(binary);
                    });

                    if (isMatch)
                    {
                        var loadedProject = EnsureProjectIsLoaded(hierarchy, vsSolution);
                        return GetDebugPropsIfMatching(loadedProject, binary);
                    }
                }
            }

            return null;
        }