繁体   English   中英

禁用Visual Studio加载项选项

[英]Disable Visual Studio addin option

我正在开发Visual Studio插件。 我在Connect.cs类的OnConnection()方法中填充Visual Studio的添加选项。

现在,我想基于打开的host项目禁用添加选项。

例如,如果web project打开,我想添加选项启用。 否则应将其禁用。

connect.cs类的哪种情况event ,我可以实现此目标,如何实现?

这应该可以解决问题:

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

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的列表

要禁用您的选项,您将在openedSolution方法中的“类型”(检查GUID)上删除或添加菜单openedSolution

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM