Search code examples
visual-studio-2010powershellcomenvdte

Where are the type libraries for EnvDTE?


I am using EnvDTE in a PowerShell script to automate Visual Studio 2010. Here's a snippet of the code I use:

[void][System.Reflection.Assembly]::LoadWithPartialName("EnvDTE") # (Obsolete!) 

$DTE.MainWindow | %{$_.gettype().InvokeMember("Visible","SetProperty",$null,$_,$true)}

As I understand it, this is "late-bound" code. Based on my research, I think I need the type libraries for the EnvDTE assemblies so that I can use code in PowerShell that will allow me to access COM object methods/members directly, instead of using InvokeMember.

Where are the type libraries for EnvDTE?


Solution

  • "dte*.olb" are registered type libraries located in C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\ (more precisely, respective path can be looked up in registry usign LIBID, e.g. in HKEY_CLASSES_ROOT\TypeLib{80CC9F66-E7D8-4DDD-85B6-D9E6CD0E93E2}\8.0\0\win32). Type library names are "Microsoft Development Environment ". For example:

    enter image description here

    // Generated .IDL file (by the OLE/COM Object Viewer)
    // 
    // typelib filename: dte80a.olb
    
    [
      uuid(80CC9F66-E7D8-4DDD-85B6-D9E6CD0E93E2),
      version(8.0),
      helpstring("Microsoft Development Environment 8.0 (Version 7.0 Object Model)")
    ]
    library EnvDTE // <<----------------
    {
        // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
        importlib("stdole2.tlb");
    
        // Forward declare all types defined in this typelib
        interface _DTE;
        interface Windows;
        interface Window;
        [...]
    

    UPDATE. Having a look at what type information MainWindow reports, I see a difference between information reported by VisualStudio.DTE.9.0 and VisualStudio.DTE.10.0 (VS2010 and on).

    Good MainWindow reports (reference code) reference to valid registered type library, and newer "bad" MainWindow reports containing type library {F11EBD51-0035-3612-BFB9-7D9ED680A986} in Microsoft.VisualStudio.Platform.WindowManagement.dll, which is not registered and does not have valid disk image (resumably created dynamically).

    Trying VisualStudio.DTE.9.0
    nTypeInfoCount 1
    pTypeInfo 0x005CAF8C
    pTypeLib 0x005CB064, nTypeLibIndex 67
    sName "EnvDTE80", sDocumentation "Microsoft Development Environment 8.0"
    pLibAttr->guid {1A31287A-4D7D-413E-8E32-3B374931BD89}, lcid 0x0000, syskind 1, wMajorVerNum 8, wMinorVerNum 0, wLibFlags 0x8
    vVisible.vt 0xB
    
    Trying VisualStudio.DTE.10.0
    nTypeInfoCount 1
    pTypeInfo 0x005CB1CC
    pTypeLib 0x005CB2A4, nTypeLibIndex 8
    sName "Microsoft_VisualStudio_Platform_WindowManagement", sDocumentation "Microsoft.VisualStudio.Platform.WindowManagement.dll"
    pLibAttr->guid {F11EBD51-0035-3612-BFB9-7D9ED680A986}, lcid 0x0000, syskind 1, wMajorVerNum 10, wMinorVerNum 0, wLibFlags 0x0
    vVisible.vt 0xB
    

    It looks like PowerShell is unable to use this type information and your only workaround is to use InvokeHelper.