public void SetProjectTypeGuids(EnvDTE.Project proj) { string templatesDir = Path.Combine(GetTemplateBasePath(), "Items.Cache"); //Helpers.EnsureGaxPackageRegistration("{14822709-B5A1-4724-98CA-57A101D1B079}", GetPackageGuid(), templatesDir, GetPackageCaption()); Helpers.EnsureGaxPackageRegistration("{14822709-B5A1-4724-98CA-57A101D1B079}", "{14822709-B5A1-4724-98CA-57A101D1B079}", templatesDir, GetPackageCaption()); string projectTypeGuids = ""; object service = null; Microsoft.VisualStudio.Shell.Interop.IVsSolution solution = null; Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy = null; Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject aggregatableProject = null; int result = 0; service = GetService(typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)); solution = (Microsoft.VisualStudio.Shell.Interop.IVsSolution)service; result = solution.GetProjectOfUniqueName(proj.UniqueName, out hierarchy); if (result == 0) { aggregatableProject = (Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject)hierarchy; result = aggregatableProject.GetAggregateProjectTypeGuids(out projectTypeGuids); //workflows if (!projectTypeGuids.ToUpper().Contains("{14822709-B5A1-4724-98CA-57A101D1B079}")) { if (projectTypeGuids == "") { projectTypeGuids = "{14822709-B5A1-4724-98CA-57A101D1B079}"; } else { projectTypeGuids = "{14822709-B5A1-4724-98CA-57A101D1B079}" + ";" + projectTypeGuids; } } //csharp if (!projectTypeGuids.ToUpper().Contains("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")) { if (projectTypeGuids != "") { projectTypeGuids += ";"; } projectTypeGuids += "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"; } aggregatableProject.SetAggregateProjectTypeGuids(projectTypeGuids); } }
private System.Type GetTypeByName(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package, string name) { System.IServiceProvider serviceProvider = package as System.IServiceProvider; Microsoft.VisualStudio.Shell.Design.DynamicTypeService typeService = serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Design.DynamicTypeService)) as Microsoft.VisualStudio.Shell.Design.DynamicTypeService; Microsoft.VisualStudio.Shell.Interop.IVsSolution sln = serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)) as Microsoft.VisualStudio.Shell.Interop.IVsSolution; Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hier; sln.GetProjectOfUniqueName(DTE.ActiveDocument.ProjectItem.ContainingProject.UniqueName, out hier); return(typeService.GetTypeResolutionService(hier).GetType(name, true)); }
internal static string GetProjectTypeGuids(EnvDTE.Project proj) { string projectTypeGuids = ""; object service = null; Microsoft.VisualStudio.Shell.Interop.IVsSolution solution = null; Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy = null; Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject aggregatableProject = null; int result = 0; service = GetService(proj.DTE, typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)); solution = (Microsoft.VisualStudio.Shell.Interop.IVsSolution)service; result = solution.GetProjectOfUniqueName(proj.UniqueName, out hierarchy); if (result == 0) { aggregatableProject = (Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject)hierarchy; result = aggregatableProject.GetAggregateProjectTypeGuids(out projectTypeGuids); } return(projectTypeGuids); }
private string AdjustPath(string fullPath) { // Right now the only adjustment is for CPS-based project systems which open their project files in a // temporary location. There are several of these, such as .csproj, .vbproj, .shproj, and .fsproj, and more // could appear in the future. if (!fullPath.EndsWith("proj", StringComparison.Ordinal)) { return(fullPath); } // CPS will open the file in %TEMP%\{random name}\{ProjectFileName} string directoryName = Path.GetDirectoryName(fullPath); if (string.IsNullOrEmpty(directoryName)) { return(fullPath); } directoryName = Path.GetDirectoryName(directoryName); if (!Path.GetTempPath().Equals(directoryName + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) { return(fullPath); } IVsSolution solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution; if (solution == null) { return(fullPath); } if (!ErrorHandler.Succeeded(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, Guid.Empty, out IEnumHierarchies ppenum)) || ppenum == null) { return(fullPath); } List <string> projectFiles = new List <string>(); IVsHierarchy[] hierarchies = new IVsHierarchy[1]; while (true) { int hr = ppenum.Next((uint)hierarchies.Length, hierarchies, out uint fetched); if (!ErrorHandler.Succeeded(hr)) { return(fullPath); } for (uint i = 0; i < fetched; i++) { if (!(hierarchies[0] is IVsProject project)) { continue; } if (!ErrorHandler.Succeeded(project.GetMkDocument((uint)VSConstants.VSITEMID.Root, out string projectFilePath))) { continue; } if (!Path.GetFileName(projectFilePath).Equals(Path.GetFileName(fullPath), StringComparison.Ordinal)) { continue; } projectFiles.Add(projectFilePath); } if (hr != VSConstants.S_OK) { // No more projects break; } } switch (projectFiles.Count) { case 0: // No matching project file found in solution return(fullPath); case 1: // Exactly one matching project file found in solution return(projectFiles[0]); default: // Multiple project files found in solution; try to find one with a matching file size long desiredSize = new FileInfo(fullPath).Length; foreach (var projectFilePath in projectFiles) { if (File.Exists(projectFilePath) && new FileInfo(projectFilePath).Length == desiredSize) { return(projectFilePath); } } // No results found return(fullPath); } }