2013-07-03 58 views
1

我正在开发Visual Studio插件。 Connect.cs类的OnConnection()方法填写视觉工作室加入选项。禁用Visual Studio插件选项

现在我想根据打开的host项目禁用加入选项。

例如,如果web project处于打开状态,我想添加选项启用。否则应该禁用。

其中eventconnect.cs类我可以做到这一点,怎么样?

回答

1

这应该做的伎俩:

_applicationObject.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(openedSolution); 
    _applicationObject.Events.SolutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(closedSolution); 

“内部” REFFERENCE在MSDN:http://msdn.microsoft.com/de-de/library/EnvDTE.aspx

您可以决定项目的类型与代码(从http://www.mztools.com/articles/2007/mz2007016.aspx):

public 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, hierarchy); 

     if (result == 0) 
     { 
      aggregatableProject = (Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject)hierarchy; 
      result = aggregatableProject.GetAggregateProjectTypeGuids(projectTypeGuids); 
     } 

     return projectTypeGuids; 

    } 

    public object GetService(object serviceProvider, System.Type type) 
    { 
     return GetService(serviceProvider, type.GUID); 
    } 

    public object GetService(object serviceProviderObject, System.Guid guid) 
    { 

     object service = null; 
     Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider = null; 
     IntPtr serviceIntPtr; 
     int hr = 0; 
     Guid SIDGuid; 
     Guid IIDGuid; 

     SIDGuid = guid; 
     IIDGuid = SIDGuid; 
     serviceProvider = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)serviceProviderObject; 
     hr = serviceProvider.QueryService(SIDGuid, IIDGuid, serviceIntPtr); 

     if (hr != 0) 
     { 
      System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hr); 
     } 
     else if (!serviceIntPtr.Equals(IntPtr.Zero)) 
     { 
      service = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(serviceIntPtr); 
      System.Runtime.InteropServices.Marshal.Release(serviceIntPtr); 
     } 

     return service; 
    } 

您可以找到已知的GUID列表here

要禁用您的选项,您可以删除或添加有关类型(检查GUID)的菜单项openedSolution方法

+0

Zumbe:如何禁用选项? – ChandniShah

+0

这是一个菜单条目吗? –

+0

加入选项来当我右键点击解决方案/项目 – ChandniShah