private void EnumerateSharedProjectsInSolution(IVsSolution solution) { ThreadHelper.ThrowIfNotOnUIThread(); int hr = solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, Guid.Empty, out IEnumHierarchies enumHierarchies); if (ErrorHandler.Failed(hr)) { return; } IVsHierarchy[] hierarchies = new IVsHierarchy[1]; while (ErrorHandler.Succeeded(enumHierarchies.Next(1, hierarchies, out uint fetchedCount)) && (fetchedCount == 1)) { if (hierarchies[0].IsSharedAssetsProject()) { hierarchies[0].GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_Name, out object result); WriteToOutputPane("Shared project: " + result as string); WriteToOutputPane("\tProject items: "); foreach (var itemId in GetProjectItems(hierarchies[0], (uint)VSConstants.VSITEMID.Root)) { hr = hierarchies[0].GetCanonicalName(itemId, out string projectItemName); WriteToOutputPane($"\t\tName: [{projectItemName}] Item id: [{(ErrorHandler.Succeeded(hr) ? itemId.ToString() : "NULL")}]"); } WriteToOutputPane("Importing projects: "); foreach (var importingProject in hierarchies[0].EnumImportingProjects()) { importingProject.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_Name, out result); WriteToOutputPane("\t" + result as string); WriteToOutputPane("\tShared Project items: "); foreach (var itemId in GetProjectItems(importingProject, (uint)VSConstants.VSITEMID.Root)) { if (SharedProjectUtilities.IsSharedItem(importingProject, itemId)) { hr = importingProject.GetCanonicalName(itemId, out string projectItemName); WriteToOutputPane($"\t\tName: [{projectItemName}] Item id: [{(ErrorHandler.Succeeded(hr) ? itemId.ToString() : "NULL")}]"); } } } hierarchies[0].GetActiveProjectContext().GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_Name, out result); WriteToOutputPane("Active project context = " + result as string); } } }
private static IEnumerable <Guid> GetSharedProjectDependencies(IVsHierarchy hierarchy, State state) { string[] projitemsPaths; ThreadHelper.ThrowIfNotOnUIThread(); projitemsPaths = SharedProjectUtilities.GetSharedItemsImportFullPaths(hierarchy); if ((projitemsPaths is not null) && (projitemsPaths.Length > 0)) { HashSet <string> shprojPaths; // The hierarchy of the shared project is available as a property against the `IVsHierarchy` of // the item that represents the `.projitems` file. However, that property is only populated if the // shared project is already loaded. We need to find shared projects that are both loaded and unloaded, // so we can't use that property. Instead, we'll look through all of the projects in the solution and // check if the file name is the `.shproj` file that's next to the corresponding `.projitems` file. shprojPaths = projitemsPaths.Select((x) => Path.ChangeExtension(x, ".shproj")).ToHashSet(StringComparer.OrdinalIgnoreCase); foreach (var item in ((IVsSolution)state.Solution).GetAllProjectHierarchies(ProjectStateFilter.All)) { if (ErrorHandler.Succeeded(item.GetCanonicalName(VSConstants.VSITEMID_ROOT, out string fileName))) { if (shprojPaths.Contains(fileName)) { if (state.Solution.TryGetIdentifier(item, out Guid identifier)) { yield return(identifier); } } } } } }