private async Task EnsureNuGetAndVsProjectAdapterCacheAsync() { await _initLock.ExecuteNuGetOperationAsync(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (!_cacheInitialized && await IsSolutionOpenAsync()) { try { var dte = await _asyncServiceProvider.GetDTEAsync(); var supportedProjects = new List <Project>(); foreach (Project project in await EnvDTESolutionUtility.GetAllEnvDTEProjectsAsync(dte)) { if (await EnvDTEProjectUtility.IsSupportedAsync(project)) { supportedProjects.Add(project); } } foreach (var project in supportedProjects) { 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); }
public async Task <bool> DoesNuGetSupportsAnyProjectAsync() { // Do NOT initialize VSSolutionManager through this API (by calling EnsureInitializeAsync) // This is a fast check implemented specifically for right click context menu to be // quick and does not involve initializing VSSolutionManager. Otherwise it will make // the UI stop responding for right click on solution. await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // first check with DTE, and if we find any supported project, then return immediately. var dte = await _asyncServiceProvider.GetDTEAsync(); var isSupported = false; foreach (Project project in await EnvDTESolutionUtility.GetAllEnvDTEProjectsAsync(dte)) { isSupported = true; break; } return(isSupported); }
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); }