I'm trying to understand how the Visual Studio EnvDTE Interop Assemblies work, and why they have been designed this way. New assemblies contain updated/new interfaces, and the recommendation by Microsoft is to use the most recent interface in VS2017. That looks like this:
EnvDTE.DTE dte = (EnvDTE.DTE)((IServiceProvider)Host).GetCOMService(typeof(DTE));
EnvDTE80.DTE2 dte2 = (EnvDTE80)dte;
EnvDTE.Solution solution = dte2.Solution; // Returns a Solution type, not Solution2
EnvDTE80.Solution2 solution2 = (EnvDTE80.Solution2)dte2.Solution;
In that snippet,the DTE2.Solution property returns type Solution and not Solution2 as I'd have expected... You must explicitly cast to access newer interfaces, which seems odd.
I searched the registry for each GUID of the EnvDTExxx assemblies, but the only CLSIDs I found with references to any of them were the Microsoft Visual Studio DTE Object and the Microsoft Visual Studio Solution Object. Both link to EnvDTE as their type library... And I can't find any COM object that uses the newer EnvDTExxx versions. Yet I see the newest interfaced in OleView!!! :
Does this mean newer EvDTExxx Assemblies rely on the origional EnvDTE to access the actual COM component? I believe the interfaces in OleView represent the actual interfaces on the COM component... but then why wouldn't the EnvDTE type library use the updated DTE2 interface?
To add to my confusion, I discovered only EnvDTE and EnvDTE80 are decorated with the PrimaryInteropAssemblyAttribute... while EnvDTE90-100 aren't! I'm assuming because the newer interop assemblies only expose types of EnvDTE (The PIA), there won't be type conflicts? But that doesn't explain why EnvDTE80 is marked as a PIA also...I thought there could only be one PIA!
Please rescue me from my COMfusion!