46

Where are custom extensions installed in Visual Studio? I know you could get path though ExtensionManager.GetInstalledExtensions(), however it seems none of the paths found corresponds to my extension.

Matze
  • 4,433
  • 4
  • 45
  • 59
Yituo
  • 1,135
  • 2
  • 11
  • 19

2 Answers2

60

Extensions (if deployed as VSIX) will be installed to the user´s profile; each extension will be installed into a folder with a random name, for instance:

%LocalAppData%\Microsoft\VisualStudio\12.0\Extensions\s5lxc0ne.1kp

If you want to obtain the package installation path at runtime, you can obtain that information from the assembly that defines the Package class.

static string GetAssemblyLocalPathFrom(Type type)
{
    string codebase = type.Assembly.CodeBase;
    var uri = new Uri(codebase, UriKind.Absolute);
    return uri.LocalPath;
}

...

string installationPath = GetAssemblyLocalPathFrom(typeof(MyPackage));
Michael Hagar
  • 568
  • 4
  • 17
Matze
  • 4,433
  • 4
  • 45
  • 59
  • 10
    In the case that you can't find your extension in the folder describe above (like me), there are also "administrative extensions" which can be found here: \Common7\IDE\Extensions\ – Mark Spiezio Nov 02 '17 at 17:49
2

1- Find your package... Let's say your package is MyExtensionPackage.

public sealed class MyExtensionPackage : Package
{
     //...
}

public static string GetExtensionInstallationDirectoryOrNull()
{
    try
    {
        var uri = new Uri(typeof(MyExtensionPackage).Assembly.CodeBase, UriKind.Absolute);
        return Path.GetDirectoryName(uri.LocalPath);
    }
    catch 
    {
        return null;
    }
}
Alper Ebicoglu
  • 6,488
  • 1
  • 34
  • 39