DTE(vs2012) 编程相关笔记

仅作记录,方便以后查阅。


1. Reference related:

envdte 

envdte80

envdte90

envdte100 

Microsoft.VisualStudio.Shell.11.0 

...... 

 

2. Create DTE instance 

// way1 
EnvDTE80.DTE2 _dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.11.0"); 
 // way2
Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
EnvDTE80.DTE2 _dte2 = Activator.CreateInstance(visualStudioType) as EnvDTE80.DTE2; 

 

 

3. Get Service from DTE

很多时候,想取shell相关的service,但是用Package.GlobalProvider.GetService(xxx)不行,但是代码在extension和Addin里面可以,所以估计Package的使用范围有限制。

所以必须想办法从DTE去绕。 

 

IVsUIShell vsUIShell = (new ServiceProvider(DTEInstance as Microsoft.VisualStudio.OLE.Interop.IServiceProvider)).GetService(typeof(SVsShell)) as IVsUIShell;

 

 

4. Some com interface not allowed used though they are public seen by refactor 

自己动手重新包一遍,比如

 

     [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier, Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
    public interface SVsColorThemeService
    {
    }
    [ComImport, TypeIdentifier, Guid("EAB552CF-7858-4F05-8435-62DB6DF60684"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVsColorThemeService
    {
        void _VtblGap1_4();
        IVsColorThemes Themes { [return: MarshalAs(UnmanagedType.Interface)] get; }
        object ColorNames { [return: MarshalAs(UnmanagedType.Interface)] get; }
        IVsColorTheme CurrentTheme { [return: MarshalAs(UnmanagedType.Interface)] get; }
    }

 

posted @ 2012-08-24 12:23  Alen在西安  阅读(1571)  评论(0编辑  收藏  举报