public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync( ILogger _, CancellationToken __) { await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); if (AsVSProject4.References == null) { return(Array.Empty <ProjectRestoreReference>()); } var references = new List <ProjectRestoreReference>(); foreach (Reference6 r in AsVSProject4.References.Cast <Reference6>()) { if (r.SourceProject != null && await EnvDTEProjectUtility.IsSupportedAsync(r.SourceProject)) { Array metadataElements; Array metadataValues; r.GetMetadata(ReferenceMetadata, out metadataElements, out metadataValues); references.Add(ToProjectRestoreReference(new ProjectReference( uniqueName: r.SourceProject.FullName, metadataElements: metadataElements, metadataValues: metadataValues))); } } return(references); }
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 static async Task <bool> IsNuGetProjectUpgradeableAsync(NuGetProject nuGetProject, Project envDTEProject = null, bool needsAPackagesConfig = true) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (nuGetProject == null && envDTEProject == null) { return(false); } nuGetProject = nuGetProject ?? await GetNuGetProject(envDTEProject); if (nuGetProject == null) { return(false); } // check if current project is packages.config based or not var msBuildNuGetProject = nuGetProject as MSBuildNuGetProject; if (msBuildNuGetProject == null || (!msBuildNuGetProject.PackagesConfigNuGetProject.PackagesConfigExists() && needsAPackagesConfig)) { return(false); } // this further check if current project system supports VSProject4 or not which is essential to skip // projects like c++ which currently doesn't support VSProject4 implementation for PackageReference if (!msBuildNuGetProject.ProjectServices.Capabilities.SupportsPackageReferences) { return(false); } if (envDTEProject == null) { var vsmsBuildNuGetProjectSystem = msBuildNuGetProject.ProjectSystem as VsMSBuildProjectSystem; if (vsmsBuildNuGetProjectSystem == null) { return(false); } envDTEProject = vsmsBuildNuGetProjectSystem.VsProjectAdapter.Project; } if (!await EnvDTEProjectUtility.IsSupportedAsync(envDTEProject)) { return(false); } return(await IsProjectPackageReferenceCompatibleAsync(envDTEProject)); }
private void OnEnvDTEProjectRenamed(Project envDTEProject, string oldName) { NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { if (!string.IsNullOrEmpty(oldName) && await IsSolutionOpenAsync() && _solutionOpenedRaised) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); await EnsureNuGetAndVsProjectAdapterCacheAsync(); if (await EnvDTEProjectUtility.IsSupportedAsync(envDTEProject)) { RemoveVsProjectAdapterFromCache(oldName); var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(envDTEProject); await AddVsProjectAdapterToCacheAsync(vsProjectAdapter); _projectSystemCache.TryGetNuGetProject(envDTEProject.Name, out var nuGetProject); NuGetProjectRenamed?.Invoke(this, new NuGetProjectEventArgs(nuGetProject)); // VSSolutionManager susbscribes to this Event, in order to update the caption on the DocWindow Tab. // This needs to fire after NugetProjectRenamed so that PackageManagerModel has been updated with // the right project context. AfterNuGetProjectRenamed?.Invoke(this, new NuGetProjectEventArgs(nuGetProject)); } else if (await EnvDTEProjectUtility.IsSolutionFolderAsync(envDTEProject)) { // In the case where a solution directory was changed, project FullNames are unchanged. // We only need to invalidate the projects under the current tree so as to sync the CustomUniqueNames. foreach (var item in await EnvDTEProjectUtility.GetSupportedChildProjectsAsync(envDTEProject)) { RemoveVsProjectAdapterFromCache(item.FullName); var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(item); if (await vsProjectAdapter.IsSupportedAsync()) { await AddVsProjectAdapterToCacheAsync(vsProjectAdapter); } } } } }); }
private void OnEnvDTEProjectAdded(Project envDTEProject) { NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { if (await IsSolutionOpenAsync() && await EnvDTEProjectUtility.IsSupportedAsync(envDTEProject) && !EnvDTEProjectUtility.IsParentProjectExplicitlyUnsupported(envDTEProject) && _solutionOpenedRaised) { await EnsureNuGetAndVsProjectAdapterCacheAsync(); var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(envDTEProject); await AddVsProjectAdapterToCacheAsync(vsProjectAdapter); NuGetProject nuGetProject; _projectSystemCache.TryGetNuGetProject(envDTEProject.Name, out nuGetProject); NuGetProjectAdded?.Invoke(this, new NuGetProjectEventArgs(nuGetProject)); } }); }
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)) { if (await EnvDTEProjectUtility.IsSupportedAsync(project)) { isSupported = true; break; } } return(isSupported); }
public async Task <bool> IsSupportedAsync() { return(await EnvDTEProjectUtility.IsSupportedAsync(Project)); }
/// <summary> /// Determines if NuGet is used in the project. Currently, it is determined by checking if packages.config is part of the project /// </summary> /// <param name="project">The project which is checked to see if NuGet is used in it</param> public static async Task <bool> IsNuGetInUseAsync(Project project) { return(await EnvDTEProjectUtility.IsSupportedAsync(project) && File.Exists(await project.GetPackagesConfigFullPathAsync())); }
public static async Task <IEnumerable <EnvDTE.Project> > GetAllEnvDTEProjectsAsync(EnvDTE.DTE dte) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var envDTESolution = dte.Solution; if (envDTESolution == null || !envDTESolution.IsOpen) { return(Enumerable.Empty <EnvDTE.Project>()); } var envDTEProjects = new Stack <EnvDTE.Project>(); foreach (EnvDTE.Project envDTEProject in envDTESolution.Projects) { if (!EnvDTEProjectUtility.IsExplicitlyUnsupported(envDTEProject)) { envDTEProjects.Push(envDTEProject); } } var resultantEnvDTEProjects = new List <EnvDTE.Project>(); while (envDTEProjects.Any()) { var envDTEProject = envDTEProjects.Pop(); if (await EnvDTEProjectUtility.IsSupportedAsync(envDTEProject)) { resultantEnvDTEProjects.Add(envDTEProject); } else if (EnvDTEProjectUtility.IsExplicitlyUnsupported(envDTEProject)) { // do not drill down further if this project is explicitly unsupported, e.g. LightSwitch projects continue; } EnvDTE.ProjectItems envDTEProjectItems = null; try { // bug 1138: Oracle Database Project doesn't implement the ProjectItems property envDTEProjectItems = envDTEProject.ProjectItems; } catch (NotImplementedException) { continue; } // ProjectItems property can be null if the project is unloaded if (envDTEProjectItems != null) { foreach (EnvDTE.ProjectItem envDTEProjectItem in envDTEProjectItems) { try { if (envDTEProjectItem.SubProject != null) { envDTEProjects.Push(envDTEProjectItem.SubProject); } } catch (NotImplementedException) { // Some project system don't implement the SubProject property, // just ignore those } } } } return(resultantEnvDTEProjects); }