1

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

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

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

我可以在哪个课程eventconnect.cs实现这一目标以及如何实现?

4

1 回答 1

1

这应该可以解决问题:

    _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)的菜单项

于 2013-07-03T11:45:34.423 回答