private static void AddDependentProject(IDictionary <string, List <EnvDTE.Project> > dependentEnvDTEProjectsDictionary, EnvDTE.Project envDTEProject, EnvDTE.Project dependentEnvDTEProject) { Debug.Assert(ThreadHelper.CheckAccess()); string uniqueName = EnvDTEProjectInfoUtility.GetUniqueName(envDTEProject); List <EnvDTE.Project> dependentEnvDTEProjects; if (!dependentEnvDTEProjectsDictionary.TryGetValue(uniqueName, out dependentEnvDTEProjects)) { dependentEnvDTEProjects = new List <EnvDTE.Project>(); dependentEnvDTEProjectsDictionary[uniqueName] = dependentEnvDTEProjects; } dependentEnvDTEProjects.Add(dependentEnvDTEProject); }
// REVIEW: This might be inefficient, see what we can do with caching projects until references change internal static IEnumerable <EnvDTE.Project> GetDependentEnvDTEProjects(IDictionary <string, List <EnvDTE.Project> > dependentEnvDTEProjectsDictionary, EnvDTE.Project envDTEProject) { Debug.Assert(ThreadHelper.CheckAccess()); if (envDTEProject == null) { throw new ArgumentNullException(nameof(envDTEProject)); } List <Project> dependents; if (dependentEnvDTEProjectsDictionary.TryGetValue(EnvDTEProjectInfoUtility.GetUniqueName(envDTEProject), out dependents)) { return(dependents); } return(Enumerable.Empty <EnvDTE.Project>()); }
private static async Task AddBindingRedirectsAsync(VSSolutionManager vsSolutionManager, EnvDTEProject envDTEProject, AppDomain domain, HashSet <string> visitedProjects, Dictionary <string, HashSet <string> > projectAssembliesCache, IVsFrameworkMultiTargeting frameworkMultiTargeting, IDictionary <string, List <EnvDTEProject> > dependentEnvDTEProjectsDictionary, INuGetProjectContext nuGetProjectContext) { // Need to be on the UI thread string envDTEProjectUniqueName = EnvDTEProjectInfoUtility.GetUniqueName(envDTEProject); if (visitedProjects.Contains(envDTEProjectUniqueName)) { return; } if (EnvDTEProjectUtility.SupportsBindingRedirects(envDTEProject)) { await AddBindingRedirectsAsync(vsSolutionManager, envDTEProject, domain, projectAssembliesCache, frameworkMultiTargeting, nuGetProjectContext); } // Add binding redirects to all envdteprojects that are referencing this one foreach (EnvDTEProject dependentEnvDTEProject in VSSolutionManager.GetDependentEnvDTEProjects(dependentEnvDTEProjectsDictionary, envDTEProject)) { await AddBindingRedirectsAsync( vsSolutionManager, dependentEnvDTEProject, domain, visitedProjects, projectAssembliesCache, frameworkMultiTargeting, dependentEnvDTEProjectsDictionary, nuGetProjectContext); } visitedProjects.Add(envDTEProjectUniqueName); }
private async Task <bool> IsPackagesConfigBasedProjectAsync() { ThreadHelper.ThrowIfNotOnUIThread(); var dteProject = EnvDTEProjectInfoUtility.GetActiveProject(VsMonitorSelection); var uniqueName = EnvDTEProjectInfoUtility.GetUniqueName(dteProject); var nuGetProject = await SolutionManager.Value.GetNuGetProjectAsync(uniqueName); if (nuGetProject == null) { return(false); } var msBuildNuGetProject = nuGetProject as MSBuildNuGetProject; if (msBuildNuGetProject == null || !msBuildNuGetProject.PackagesConfigNuGetProject.PackagesConfigExists()) { return(false); } return(true); }
public static IVsProjectBuildSystem GetVsProjectBuildSystem(EnvDTE.Project project) { if (project == null) { throw new ArgumentNullException(nameof(project)); } return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // Get the vs solution IVsSolution solution = ServiceLocator.GetInstance <IVsSolution>(); IVsHierarchy hierarchy; var hr = solution.GetProjectOfUniqueName(EnvDTEProjectInfoUtility.GetUniqueName(project), out hierarchy); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } return hierarchy as IVsProjectBuildSystem; })); }
private async Task <IVsWindowFrame> CreateDocWindowAsync( Project project, string documentName, IVsHierarchy hier, uint itemId) { ThreadHelper.ThrowIfNotOnUIThread(); var windowFlags = (uint)_VSRDTFLAGS.RDT_DontAddToMRU | (uint)_VSRDTFLAGS.RDT_DontSaveAs; if (!await SolutionManager.Value.IsSolutionAvailableAsync()) { throw new InvalidOperationException(Resources.SolutionIsNotSaved); } var uniqueName = EnvDTEProjectInfoUtility.GetUniqueName(project); var nugetProject = await SolutionManager.Value.GetNuGetProjectAsync(uniqueName); // If we failed to generate a cache entry in the solution manager something went wrong. if (nugetProject == null) { throw new InvalidOperationException( string.Format(Resources.ProjectHasAnInvalidNuGetConfiguration, project.Name)); } // load packages.config. This makes sure that an exception will get thrown if there // are problems with packages.config, such as duplicate packages. When an exception // is thrown, an error dialog will pop up and this doc window will not be created. var installedPackages = await nugetProject.GetInstalledPackagesAsync(CancellationToken.None); var uiController = UIFactory.Value.Create(nugetProject); var model = new PackageManagerModel( uiController, isSolution: false, editorFactoryGuid: GuidList.guidNuGetEditorType); var vsWindowSearchHostfactory = await GetServiceAsync(typeof(SVsWindowSearchHostFactory)) as IVsWindowSearchHostFactory; var vsShell = await GetServiceAsync(typeof(SVsShell)) as IVsShell4; var control = new PackageManagerControl(model, Settings.Value, vsWindowSearchHostfactory, vsShell, OutputConsoleLogger.Value); var windowPane = new PackageManagerWindowPane(control); var guidEditorType = GuidList.guidNuGetEditorType; var guidCommandUI = Guid.Empty; var caption = string.Format( CultureInfo.CurrentCulture, Resx.Label_NuGetWindowCaption, project.Name); IVsWindowFrame windowFrame; var uiShell = await GetServiceAsync(typeof(SVsUIShell)) as IVsUIShell; var ppunkDocView = IntPtr.Zero; var ppunkDocData = IntPtr.Zero; var hr = 0; try { ppunkDocView = Marshal.GetIUnknownForObject(windowPane); ppunkDocData = Marshal.GetIUnknownForObject(model); hr = uiShell.CreateDocumentWindow( windowFlags, documentName, (IVsUIHierarchy)hier, itemId, ppunkDocView, ppunkDocData, ref guidEditorType, null, ref guidCommandUI, null, caption, string.Empty, null, out windowFrame); if (windowFrame != null) { WindowFrameHelper.AddF1HelpKeyword(windowFrame, keywordValue: F1KeywordValuePmUI); } } finally { if (ppunkDocView != IntPtr.Zero) { Marshal.Release(ppunkDocData); } if (ppunkDocData != IntPtr.Zero) { Marshal.Release(ppunkDocView); } } ErrorHandler.ThrowOnFailure(hr); return(windowFrame); }
/// <summary> /// Get only the direct dependencies from a project /// </summary> public static async Task <IReadOnlyList <ProjectRestoreReference> > GetDirectProjectReferences( EnvDTEProject project, IEnumerable <string> resolvedProjects, ILogger log) { return(await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() => { // DTE calls need to be done from the main thread await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var results = new List <ProjectRestoreReference>(); var itemsFactory = ServiceLocator.GetInstance <IVsEnumHierarchyItemsFactory>(); // Verify ReferenceOutputAssembly var excludedProjects = GetExcludedReferences(project, itemsFactory); var hasMissingReferences = false; // find all references in the project foreach (var childReference in GetProjectReferences(project)) { try { var reference3 = childReference as Reference3; // check if deferred projects resolved this reference, which means this is still not loaded so simply continue // We'll get this reference from deferred projects later if (reference3 != null && resolvedProjects.Contains(reference3.Name, StringComparer.OrdinalIgnoreCase)) { continue; } // Set missing reference if // 1. reference is null OR // 2. reference is not resolved which means project is not loaded or assembly not found. else if (reference3 == null || !reference3.Resolved) { // Skip missing references and show a warning hasMissingReferences = true; continue; } // Skip missing references if (childReference.SourceProject != null) { if (EnvDTEProjectUtility.HasUnsupportedProjectCapability(childReference.SourceProject)) { // Skip this shared project continue; } var childProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(childReference.SourceProject); // Skip projects which have ReferenceOutputAssembly=false if (!string.IsNullOrEmpty(childProjectPath) && !excludedProjects.Contains(childProjectPath, StringComparer.OrdinalIgnoreCase)) { var restoreReference = new ProjectRestoreReference() { ProjectPath = childProjectPath, ProjectUniqueName = childProjectPath }; results.Add(restoreReference); } } } catch (Exception ex) { // Exceptions are expected in some scenarios for native projects, // ignore them and show a warning hasMissingReferences = true; log.LogDebug(ex.ToString()); Debug.Fail("Unable to find project dependencies: " + ex.ToString()); } } if (hasMissingReferences) { // Log a generic message once per project if any items could not be resolved. // In most cases this can be ignored, but in the rare case where the unresolved // item is actually a project the restore result will be incomplete. var message = string.Format( CultureInfo.CurrentCulture, Strings.UnresolvedItemDuringProjectClosureWalk, EnvDTEProjectInfoUtility.GetUniqueName(project)); log.LogVerbose(message); } return results; })); }