2

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?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Sabuncu
  • 5,095
  • 5
  • 55
  • 89
  • 1
    Related: http://stackoverflow.com/questions/15210806/how-to-use-dte-in-powershell – David Brabant Apr 17 '15 at 06:52
  • Explorer has this great feature where you can search for any file on your hard drive. Did you try that? –  Apr 17 '15 at 14:07
  • @Will thank you for your sarcastic comment. I have the [Search Everything](http://www.voidtools.com/) engine installed, but I had been searching for `.tlb` files. Did not know type libraries were also provided in `.olb` files. Now, do you know how I can get rid of `InvokeMember` and access members/methods directly? – Sabuncu Apr 17 '15 at 15:49

1 Answers1

3

"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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thank you. Any ideas on how I can utilize this file so that I can get rid of the `InvokeMember` method of access? – Sabuncu Apr 17 '15 at 16:03
  • I am not sure about PowerShell, but I am under impression that you should be able to use member names/methods directly, since those are discoverable through COM `IDispatch` interface and type library. [Here](http://www.vistax64.com/powershell/11120-powershell-interacting-com-automation-late-binding.html) is some comment from MSFT guy from 2006 that "The powershell can't show the methods of COM objects if the ITypeInfo interface is not provided. This will be fixed soon. The workaround is to use Type.InvokeMethod". Possibly "soon" never happenned though. – Roman R. Apr 17 '15 at 16:20
  • Sorry to pester you w/ continued questions, but is EnvDTE.dll the interop assembly then? If not, that is if it's the COM assembly, how can I create a RCW using the type library? – Sabuncu Apr 17 '15 at 19:20
  • My guess is that the behavior depends on how `MainWindow` implementation reports its type information. It was correct up to VisualStudio.DTE.9.0 and they broke it afterwards. Implementation somehow does not reference the type library correctly: you know what it is and where it is, and what is the property type, however Powershell is unable to get it the way it wants. – Roman R. Apr 17 '15 at 21:47
  • Thank you. Do you think it can be fixed by customizing the RCW? – Sabuncu Apr 18 '15 at 00:51
  • See update above. It looks like `MainWindow` does not belong to `EnvDTE` any longer. Note that you succeeded in accessing `MainWindow` property itself first, which is still good, and then properties of `MainWindow` are already gone. – Roman R. Apr 18 '15 at 09:39
  • Roman, thank you so much. It'll take some time for me to digest this information after which I'd like to ask follow-up questions at your convenience. Regards. – Sabuncu Apr 18 '15 at 10:58
  • I was able to get your code running! Earlier I was having a COFF problem, but installing VS2010 SP1 fixed it. I don't have VS 9.0 on my system (so ATLENSURE fails), but commenting that out allowed me to get the VS 10.0 line to running. The output is pretty much the same, but it takes forever for the call to complete and the results to be printed. This is a good base for me for further exploration. Thanks again for making the code available. – Sabuncu Apr 20 '15 at 20:27