public async Task <IVsProjectAdapter> CreateAdapterForDeferredProjectAsync(IVsHierarchy project) { Assumes.Present(project); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var vsHierarchyItem = VsHierarchyItem.FromVsHierarchy(project); var fullProjectPath = VsHierarchyUtility.GetProjectPath(project); var uniqueName = string.Empty; _vsSolution.Value.GetUniqueNameOfProject(project, out uniqueName); var projectNames = new ProjectNames( fullName: fullProjectPath, uniqueName: uniqueName, shortName: Path.GetFileNameWithoutExtension(fullProjectPath), customUniqueName: GetCustomUniqueName(uniqueName)); var workspaceBuildProperties = new WorkspaceProjectBuildProperties( fullProjectPath, _workspaceService.Value, _threadingService); var projectTypeGuid = await _workspaceService.Value.GetProjectTypeGuidAsync(fullProjectPath); return(new VsProjectAdapter( vsHierarchyItem, projectNames, fullProjectPath, projectTypeGuid, EnsureProjectIsLoaded, workspaceBuildProperties, _threadingService, _workspaceService.Value)); }
public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(IVsHierarchy hierarchy) { Assumes.Present(hierarchy); // Get services while we might be on background thread var vsSolution = await _vsSolution.GetValueAsync(); // switch to main thread and use services we know must be done on main thread. await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var vsHierarchyItem = VsHierarchyItem.FromVsHierarchy(hierarchy); Func <IVsHierarchy, EnvDTE.Project> loadDteProject = hierarchy => VsHierarchyUtility.GetProjectFromHierarchy(hierarchy); var buildStorageProperty = vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage; var vsBuildProperties = new VsProjectBuildProperties( new Lazy <EnvDTE.Project>(() => loadDteProject(hierarchy)), buildStorageProperty, _threadingService); var fullProjectPath = VsHierarchyUtility.GetProjectPath(hierarchy); var projectNames = await ProjectNames.FromIVsSolution2(fullProjectPath, (IVsSolution2)vsSolution, hierarchy, CancellationToken.None); return(new VsProjectAdapter( vsHierarchyItem, projectNames, fullProjectPath, loadDteProject, vsBuildProperties, _threadingService)); }
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); }