Finding a Home Directory for Visual Studio 2010 Extensions

I am making changes to the Visual Studio wizard, which creates a project from a template, and it needs to add an assembly reference for the project, which is also in the extension directory. Therefore, I need to install <hintpath>.

I was not able to figure out how a working VS extension can detect its extension directory, which is a directory name like this:

% USERPROFILE% \ AppData \ Local \ Microsoft \ VisualStudio \ 10.0 \ Extensions \ mycomp \ myExtension

Using System.Reflection.Assembly.GetExecutingAssembly().CodeBasegives:

"C: \ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ myCompany.myExtension \ v4.0_1.0.0.0__936015a19c3638eb \ myCompany.myExtension.dll"

Unfortunately not useful. Usage is GetCallingAssembly()not better - it points to another directory in MSIL_GAC.

Is there a Visual Studio interface that returns this information? I could not find him.

If this is not possible, is it possible, at least, to determine whether the extension in the experimental instance works against the non-experimental one? I could use this information to find a directory of extensions.

+4
source share
2 answers

Maybe take a look IInstalledExtension.InstallPath. You can get IInstalledExtensionthrough IVsExtensionManager.

Unfortunately, the post in the notes suggests that this is the wrong way to do something:

Although this API supports the Extension Manager infrastructure, we recommend that you do not use it because it is subject to change.

EDIT: Here's the code:

    static IVsExtensionManager GetExtensionManager()
    {
        return myPackage.GetService(System.typeof(IVsExtensionManager)) as IVsExtensionManager;
    }
    static IInstalledExtension GetExtension(string identifier)
    {
        return GetExtensionManager().GetInstalledExtension(identifier);
    }
    static string GetExtensionDirectory(string identifier)
    {
        return GetExtension(identifier).InstallPath;
    }

string identifier - , "ID" source.extension.vsixmanifest. GUID .

+4

, ...

Extension Manager, , , , :

fooobar.com/questions/1102151/...

http://blog.ninlabs.com/2011/04/auto-update-visual-studio-extensions/

, CodeGenerator Asp.Net.Scaffolding . , ...

var path = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "MyPath");

Simples

+1

All Articles