locked
Accessing Visual Studio MEF components/IComponentModel in a remotely controlled Visual Studio instance RRS feed

  • Question

  • For an integration test scenario I am trying to start/control a Visual Studio instance remotely and access some of its public MEF components.

    Starting and controlling an instance and accessing services via the DTE works fine:

        var dte = Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.DTE.15.0", true), true) as DTE;
        ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte);
        IVsActivityLog log = sp.GetService(typeof(SVsActivityLog)) as IVsActivityLog;

    What doesn't work is the standard way of getting the `IComponentModel` which can in turned be used to access the MEF components. `GetService()` returns something but the cast results in `null`:

        var componentModel = sp.GetService(typeof(SComponentModel)) as IComponentModel

    Is there another way of getting access to the MEF components or is this scenario not supported?


    Thursday, July 27, 2017 5:30 PM

All replies

  • Hi Christian Klauss,

    According to your description, I find the following thread with the similar issue, which provide a solution for your reference.

    Please check if the GAC for versions of this DLL has two version. Please check it via the Nuget package manager, I installed version 15.0.0.0 of the DLL. But I already had a 14.0.0.0 version. I removed 15.0.0.0 from the GAC and from the references of my project, then added the existing 14.0.0.0 reference. Casts without a problem now.

    https://stackoverflow.com/questions/42514485/roslyn-in-a-vsix-project-unable-to-cast-object-of-type-componentmodel-to-icompo

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 28, 2017 5:29 AM
  • Hi Cole Wu,

    Cleaned my project re-installed all NuGet packages and checked my GAC (the DLL is not there): this seems to be a different problem.

    I just stumbled across this on stackoverflow which seems to be a similar scenario with the same error I am getting (when I replace the example code above with a direct cast) albeit with Visual Studio 2013. Sadly no solution provided is provided there.

    https://stackoverflow.com/questions/37410619/how-can-you-automate-the-nuget-services-manager-from-envdte-in-a-command-line-to

    Friday, July 28, 2017 7:28 AM
  • Hi Christian Klauss,

    Based on the link you are providing, it seems that op write related code out of visual studio, it seems that it is a console app instead of visual studio extensions, so it could not get dte object from console application.

    Best regards,

    Cole


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 16, 2017 8:56 AM
  • Hi Christian,

    Unfortunately, you cannot do this via a remote process. Most of the internal interfaces registered with and utilized by the IDE process (devenv.exe), like the IComponentModel, IVsHierarchy, IVsShell, etc... cannot be marshalled across processes.

    The only interfaces you can retrieve/utilize out of process, would be the automation interfaces found in the EnvDTE, VSLangProj, or similar namespaces. Basically, the COM automation interfaces.

    Sincerely,


    Ed Dore

    Sunday, August 20, 2017 9:17 PM