3

In previous versions of Visual Studio I could use the following code to retrieve information about a certain installed extension (vsix):

IVsExtensionManager manager = ServiceProvider.GlobalProvider.GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;
if (manager != null)
{
    VsExtension extension = new VsExtension();
    IInstalledExtension info = manager.GetInstalledExtension(cExtensionProductId);
}

In the new Visual Studio 2017 version, the 'manager' variable is always null. Microsoft changed the way to retrieve the information (they no longer use the system registry), but I can't find another way to retrieve the info.

Do you know where I can find more information and/or provide a sample of the new implementation?

Thank you in advance!

Odrai
  • 2,163
  • 2
  • 31
  • 62

2 Answers2

2

Please check that for VS 2017 you are using VS 2017 specific references to the extension manager. It should be Microsoft.VisualStudio.ExtensionManager.dll and Microsoft.VisualStudio.ExtensionEngine.dll.

For a working example see https://vlasovstudio.com/visual-commander/commands.html#ExtensionsList.

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66
  • Using the code of the example results in a "System.InvalidCastException: 'Unable to cast object of type 'Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService' to type 'Microsoft.VisualStudio.ExtensionManager.IVsExtensionManager'.' " – Odrai Oct 15 '17 at 08:36
  • Adding both dlls, ExtensionManager.dll and ExtensionEngine.dll, results in the following error: CS0433 The type 'IInstalledExtension' exists in both 'Microsoft.VisualStudio.ExtensionEngine, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.ExtensionManager, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' – Odrai Oct 15 '17 at 08:38
  • Microsoft.VisualStudio.ExtensionManager should be Version=15.0.0.0 as well. – Sergey Vlasov Oct 15 '17 at 17:31
  • Thank you for the information! I finally found the location of the Microsoft.VisualStudio.ExtensionManager.dll v.15.0.0.0. – Odrai Oct 15 '17 at 18:12
  • 2
    Location of Microsoft.VisualStudio.ExtensionManager.dll: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ – Odrai Oct 15 '17 at 18:22
  • How did you know developers need to use Microsoft.VisualStudio.ExtensionEngine.dll? – Odrai Oct 15 '17 at 18:24
  • @Odrai I'm unfortunately can't currently recall how I discovered Microsoft.VisualStudio.ExtensionEngine.dll. – Sergey Vlasov Oct 16 '17 at 04:24
  • My Microsoft.VisualStudio.ExtensionManager.dll was in: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PrivateAssemblies – inliner49er Nov 09 '18 at 21:38
0

Is the ServiceProvider.GlobalProvider.GetService(typeof(SVsExtensionManager)) returns null ? or "as IVsExtensionManager" becomes null ?

Oleg Skripnyak
  • 301
  • 2
  • 13