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); } }
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); }
public static string GetProjectTypeGuids(Project proj) { string sProjectTypeGuids = string.Empty; object objService; Microsoft.VisualStudio.Shell.Interop.IVsSolution objIVsSolution; Microsoft.VisualStudio.Shell.Interop.IVsHierarchy objIVsHierarchy = null; Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject objIVsAggregatableProject; int iResult; //objService = GetService(proj.DTE, typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)); objService = Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)); objIVsSolution = objService as Microsoft.VisualStudio.Shell.Interop.IVsSolution; iResult = objIVsSolution.GetProjectOfUniqueName(proj.UniqueName, out objIVsHierarchy); if (iResult == 0) { objIVsAggregatableProject = objIVsHierarchy as Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject; if (null != objIVsAggregatableProject) { iResult = objIVsAggregatableProject.GetAggregateProjectTypeGuids(out sProjectTypeGuids); } } return(sProjectTypeGuids); }
protected virtual object CreateDocumentView(string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, bool createdDocData, out string editorCaption, out Guid cmdUI) { //Init out params editorCaption = string.Empty; cmdUI = Guid.Empty; if (string.IsNullOrEmpty(physicalView)) { // create code window as default physical view return(CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI)); } // We couldn't create the view // Return special error code so VS can try another editor factory. throw Marshal.GetExceptionForHR(VSConstants.VS_E_UNSUPPORTEDFORMAT); }
/// <summary> /// /// </summary> /// <param name="grfCreateDoc"></param> /// <param name="pszMkDocument"></param> /// <param name="pszPhysicalView"></param> /// <param name="pvHier"></param> /// <param name="itemid"></param> /// <param name="punkDocDataExisting"></param> /// <param name="ppunkDocView"></param> /// <param name="ppunkDocData"></param> /// <param name="pbstrEditorCaption"></param> /// <param name="pguidCmdUI"></param> /// <param name="pgrfCDW"></param> /// <returns></returns> public virtual int CreateEditorInstance( uint createEditorFlags, string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IntPtr docDataExisting, out IntPtr docView, out IntPtr docData, out string editorCaption, out Guid commandUIGuid, out int createDocumentWindowFlags) { // Initialize output parameters docView = IntPtr.Zero; docData = IntPtr.Zero; commandUIGuid = Guid.Empty; createDocumentWindowFlags = 0; editorCaption = null; // Validate inputs if ((createEditorFlags & (uint)(VSConstants.CEF.OpenFile | VSConstants.CEF.Silent)) == 0) { return(VSConstants.E_INVALIDARG); } if (docDataExisting != IntPtr.Zero && _promptEncodingOnLoad) { return(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } // Get a text buffer IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker); // Assign docData IntPtr to either existing docData or the new text buffer if (docDataExisting != IntPtr.Zero) { docData = docDataExisting; Marshal.AddRef(docData); } else { docData = Marshal.GetIUnknownForObject(textLines); } try { object docViewObject = CreateDocumentView(documentMoniker, physicalView, hierarchy, itemid, textLines, docDataExisting == IntPtr.Zero, out editorCaption, out commandUIGuid); docView = Marshal.GetIUnknownForObject(docViewObject); } finally { if (docView == IntPtr.Zero) { if (docDataExisting != docData && docData != IntPtr.Zero) { // Cleanup the instance of the docData that we have addref'ed Marshal.Release(docData); docData = IntPtr.Zero; } } } return(VSConstants.S_OK); }
protected virtual object CreateDocumentView(string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, bool createdDocData, out string editorCaption, out Guid cmdUI) { //Init out params editorCaption = string.Empty; cmdUI = Guid.Empty; if (string.IsNullOrEmpty(physicalView)) { // create code window as default physical view return CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI); } // We couldn't create the view // Return special error code so VS can try another editor factory. throw Marshal.GetExceptionForHR(VSConstants.VS_E_UNSUPPORTEDFORMAT); }
/// <summary> /// /// </summary> /// <param name="grfCreateDoc"></param> /// <param name="pszMkDocument"></param> /// <param name="pszPhysicalView"></param> /// <param name="pvHier"></param> /// <param name="itemid"></param> /// <param name="punkDocDataExisting"></param> /// <param name="ppunkDocView"></param> /// <param name="ppunkDocData"></param> /// <param name="pbstrEditorCaption"></param> /// <param name="pguidCmdUI"></param> /// <param name="pgrfCDW"></param> /// <returns></returns> public virtual int CreateEditorInstance( uint createEditorFlags, string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IntPtr docDataExisting, out IntPtr docView, out IntPtr docData, out string editorCaption, out Guid commandUIGuid, out int createDocumentWindowFlags) { // Initialize output parameters docView = IntPtr.Zero; docData = IntPtr.Zero; commandUIGuid = Guid.Empty; createDocumentWindowFlags = 0; editorCaption = null; // Validate inputs if ((createEditorFlags & (uint)(VSConstants.CEF.OpenFile | VSConstants.CEF.Silent)) == 0) { return VSConstants.E_INVALIDARG; } if (docDataExisting != IntPtr.Zero && _promptEncodingOnLoad) return VSConstants.VS_E_INCOMPATIBLEDOCDATA; // Get a text buffer IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker); // Assign docData IntPtr to either existing docData or the new text buffer if (docDataExisting != IntPtr.Zero) { docData = docDataExisting; Marshal.AddRef(docData); } else { docData = Marshal.GetIUnknownForObject(textLines); } try { object docViewObject = CreateDocumentView(documentMoniker, physicalView, hierarchy, itemid, textLines, docDataExisting == IntPtr.Zero, out editorCaption, out commandUIGuid); docView = Marshal.GetIUnknownForObject(docViewObject); } finally { if (docView == IntPtr.Zero) { if (docDataExisting != docData && docData != IntPtr.Zero) { // Cleanup the instance of the docData that we have addref'ed Marshal.Release(docData); docData = IntPtr.Zero; } } } return VSConstants.S_OK; }
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); } }
public static bool IsSupportedProject(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy project) { return(IsSupportedProject(project?.GetExtObject() as EnvDTE.Project)); }