How to get installed VisualStudio extensions programmatically?
Asked Answered
N

2

6

How can I get a list of installed VisualStudio extensions? Somehow through DTE? Just the names would be fair enough.

Numerate answered 28/1, 2016 at 20:51 Comment(0)
U
6

Does this help:

System.IServiceProvider serviceProvider = package as System.IServiceProvider;
    Microsoft.VisualStudio.ExtensionManager.IVsExtensionManager em =
       (Microsoft.VisualStudio.ExtensionManager.IVsExtensionManager)serviceProvider.GetService(
            typeof(Microsoft.VisualStudio.ExtensionManager.SVsExtensionManager));

    string result = "";
    foreach(Microsoft.VisualStudio.ExtensionManager.IInstalledExtension i in em.GetInstalledExtensions())
    {
        Microsoft.VisualStudio.ExtensionManager.IExtensionHeader h = i.Header;
        if (!h.SystemComponent)
            result += h.Name + " (by " + h.Author + ") v" + h.Version + " " + h.MoreInfoUrl + System.Environment.NewLine;
    }

Copied from https://vlasovstudio.com/visual-commander/commands.html #20.

Utricle answered 28/1, 2016 at 21:47 Comment(4)
Not sure how this can be the answer when it doesnt use the DTE.Tunable
why does it have to?Numerate
> Somehow through DTE?Tunable
That was a question not a request ;-) I think you misunderstood :-)Utricle
S
6

Another possibility, if you don't want DTE, because you are not running from within Visual Studio or are concerned about performance you can query the extensions from the file system / registry:

For User Extensions %LocalAppData%\Microsoft\VisualStudio*.vsix

For General Extensions \Common7\IDE\Extensions*.vsix

IF you want to be 100% correct you can look up the paths in \Common7\IDE\devenv.pkgdef

NOTE: There can be additional paths in the PkgDefSearchPath.

To check wether a User Extensions is enabled or not you have to query the registry: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\ExtensionManager\EnabledExtensions

There are some other rules that apply, which you can find in this blog from Microsoft: http://blogs.msdn.com/b/visualstudio/archive/2010/02/19/how-vsix-extensions-are-discovered-and-loaded-in-vs-2010.aspx

Skewness answered 28/1, 2016 at 22:3 Comment(2)
Thanks. Nice alternative. My question was not detailed enough, but I'll also need to know if the extension is enabled... Still voted up =)Numerate
I think \Common7\IDE\devenv.pkgdef should be \Common7\IDE\master.pkgdef, at least on Visual Studio 2017. This will also show that you need CommonExtensions folder as well, which contains most Microsoft's common extensions (like language services) in VS 2017.Vernavernacular

© 2022 - 2024 — McMap. All rights reserved.