Beispiel #1
0
 public EnvDTEProjectName(EnvDTEProject envDTEProject)
 {
     FullName         = envDTEProject.FullName;
     UniqueName       = EnvDTEProjectUtility.GetUniqueName(envDTEProject);
     ShortName        = EnvDTEProjectUtility.GetName(envDTEProject);
     CustomUniqueName = EnvDTEProjectUtility.GetCustomUniqueName(envDTEProject);
 }
        public EnvDTEProjectName(EnvDTEProject envDTEProject)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            FullName         = envDTEProject.FullName;
            UniqueName       = EnvDTEProjectUtility.GetUniqueName(envDTEProject);
            ShortName        = EnvDTEProjectUtility.GetName(envDTEProject);
            CustomUniqueName = EnvDTEProjectUtility.GetCustomUniqueName(envDTEProject);
        }
Beispiel #3
0
        private static void AddDependentProject(IDictionary <string, List <EnvDTEProject> > dependentEnvDTEProjectsDictionary,
                                                EnvDTEProject envDTEProject, EnvDTEProject dependentEnvDTEProject)
        {
            string uniqueName = EnvDTEProjectUtility.GetUniqueName(envDTEProject);

            List <EnvDTEProject> dependentEnvDTEProjects;

            if (!dependentEnvDTEProjectsDictionary.TryGetValue(uniqueName, out dependentEnvDTEProjects))
            {
                dependentEnvDTEProjects = new List <EnvDTEProject>();
                dependentEnvDTEProjectsDictionary[uniqueName] = dependentEnvDTEProjects;
            }
            dependentEnvDTEProjects.Add(dependentEnvDTEProject);
        }
Beispiel #4
0
        public static IVsHierarchy ToVsHierarchy(Project project)
        {
            IVsHierarchy hierarchy;

            // Get the vs solution
            IVsSolution solution = ServiceLocator.GetInstance <IVsSolution>();
            int         hr       = solution.GetProjectOfUniqueName(EnvDTEProjectUtility.GetUniqueName(project), out hierarchy);

            if (hr != NuGetVSConstants.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return(hierarchy);
        }
Beispiel #5
0
        /// <summary>
        /// Factory method initializing instance of <see cref="ProjectNames"/> with values retrieved from a DTE project.
        /// </summary>
        /// <param name="dteProject">DTE project to get project names for.</param>
        /// <returns>New instance of <see cref="ProjectNames"/>.</returns>
        public static ProjectNames FromDTEProject(EnvDTE.Project dteProject)
        {
            if (dteProject == null)
            {
                throw new ArgumentNullException(nameof(dteProject));
            }

            Debug.Assert(ThreadHelper.CheckAccess());

            return(new ProjectNames(
                       fullName: dteProject.FullName,
                       uniqueName: EnvDTEProjectUtility.GetUniqueName(dteProject),
                       shortName: EnvDTEProjectUtility.GetName(dteProject),
                       customUniqueName: EnvDTEProjectUtility.GetCustomUniqueName(dteProject)));
        }
        public static VsHierarchyItem GetHierarchyItemForProject(Project project)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            IVsHierarchy hierarchy;

            // Get the solution
            IVsSolution solution = ServiceLocator.GetGlobalService <SVsSolution, IVsSolution>();
            int         hr       = solution.GetProjectOfUniqueName(EnvDTEProjectUtility.GetUniqueName(project), out hierarchy);

            if (hr != VSConstants.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return(new VsHierarchyItem(hierarchy));
        }
Beispiel #7
0
        private static void AddDependentProject(IDictionary <string, List <EnvDTE.Project> > dependentEnvDTEProjectsDictionary,
                                                EnvDTE.Project envDTEProject, EnvDTE.Project dependentEnvDTEProject)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            string uniqueName = EnvDTEProjectUtility.GetUniqueName(envDTEProject);

            List <EnvDTE.Project> dependentEnvDTEProjects;

            if (!dependentEnvDTEProjectsDictionary.TryGetValue(uniqueName, out dependentEnvDTEProjects))
            {
                dependentEnvDTEProjects = new List <EnvDTE.Project>();
                dependentEnvDTEProjectsDictionary[uniqueName] = dependentEnvDTEProjects;
            }
            dependentEnvDTEProjects.Add(dependentEnvDTEProject);
        }
Beispiel #8
0
        // REVIEW: This might be inefficient, see what we can do with caching projects until references change
        internal static IEnumerable <EnvDTEProject> GetDependentEnvDTEProjects(IDictionary <string, List <EnvDTEProject> > dependentEnvDTEProjectsDictionary, EnvDTEProject envDTEProject)
        {
            if (envDTEProject == null)
            {
                throw new ArgumentNullException("project");
            }

            List <Project> dependents;

            if (dependentEnvDTEProjectsDictionary.TryGetValue(EnvDTEProjectUtility.GetUniqueName(envDTEProject), out dependents))
            {
                return(dependents);
            }

            return(Enumerable.Empty <EnvDTEProject>());
        }
Beispiel #9
0
        // REVIEW: This might be inefficient, see what we can do with caching projects until references change
        internal static IEnumerable <EnvDTEProject> GetDependentEnvDTEProjects(IDictionary <string, List <EnvDTEProject> > dependentEnvDTEProjectsDictionary, EnvDTEProject envDTEProject)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            if (envDTEProject == null)
            {
                throw new ArgumentNullException(nameof(envDTEProject));
            }

            List <Project> dependents;

            if (dependentEnvDTEProjectsDictionary.TryGetValue(EnvDTEProjectUtility.GetUniqueName(envDTEProject), out dependents))
            {
                return(dependents);
            }

            return(Enumerable.Empty <EnvDTEProject>());
        }
        public static async Task CollapseAllNodesAsync(ISolutionManager solutionManager, IDictionary <string, ISet <VsHierarchyItem> > ignoreNodes)
        {
            // this operation needs to execute on UI thread
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var dte      = ServiceLocator.GetInstance <DTE>();
            var projects = dte.Solution.Projects;

            foreach (Project project in projects)
            {
                ISet <VsHierarchyItem> expandedNodes;
                if (ignoreNodes.TryGetValue(EnvDTEProjectUtility.GetUniqueName(project), out expandedNodes)
                    &&
                    expandedNodes != null)
                {
                    CollapseProjectHierarchyItems(project, expandedNodes);
                }
            }
        }
        public static async TaskExpandedNodes GetAllExpandedNodesAsync(ISolutionManager solutionManager)
        {
            // this operation needs to execute on UI thread
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var dte      = ServiceLocator.GetInstance <DTE>();
            var projects = dte.Solution.Projects;

            var results = new Dictionary <string, ISet <VsHierarchyItem> >(StringComparer.OrdinalIgnoreCase);

            foreach (Project project in projects)
            {
                ICollection <VsHierarchyItem> expandedNodes =
                    GetExpandedProjectHierarchyItems(project);
                Debug.Assert(!results.ContainsKey(EnvDTEProjectUtility.GetUniqueName(project)));
                results[EnvDTEProjectUtility.GetUniqueName(project)] =
                    new HashSet <VsHierarchyItem>(expandedNodes);
            }
            return(results);
        }
Beispiel #12
0
        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 = EnvDTEProjectUtility.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);
        }
        /// <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 = EnvDTEProjectUtility.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,
                        EnvDTEProjectUtility.GetUniqueName(project));

                    log.LogVerbose(message);
                }

                return results;
            }));
        }