private async Task EnsureNuGetAndVsProjectAdapterCacheAsync() { await _initLock.ExecuteNuGetOperationAsync(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsSolution ivsSolution = await _asyncVSSolution.GetValueAsync(); if (!_cacheInitialized && IsSolutionOpenFromVSSolution(ivsSolution)) { try { if (await _featureFlagService.IsFeatureEnabledAsync(NuGetFeatureFlagConstants.NuGetSolutionCacheInitilization)) { foreach (var hierarchy in VsHierarchyUtility.GetAllLoadedProjects(ivsSolution)) { try { var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(hierarchy); await AddVsProjectAdapterToCacheAsync(vsProjectAdapter); } catch (Exception e) { // Ignore failed projects. _logger.LogWarning($"The project {VsHierarchyUtility.GetProjectPath(hierarchy)} failed to initialize as a NuGet project."); _logger.LogError(e.ToString()); } // Consider that the cache is initialized only when there are any projects to add. _cacheInitialized = true; } } else { var dte = await _dte.GetValueAsync(); foreach (var project in await EnvDTESolutionUtility.GetAllEnvDTEProjectsAsync(dte)) { try { var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(project); await AddVsProjectAdapterToCacheAsync(vsProjectAdapter); } catch (Exception e) { // Ignore failed projects. _logger.LogWarning($"The project {project.Name} failed to initialize as a NuGet project."); _logger.LogError(e.ToString()); } // Consider that the cache is initialized only when there are any projects to add. _cacheInitialized = true; } } await SetDefaultProjectNameAsync(); } catch { _projectSystemCache.Clear(); _cacheInitialized = false; DefaultNuGetProjectName = null; throw; } } }, CancellationToken.None); }