Finding the home directory for a Visual Studio 2010 extension

你。 提交于 2019-12-05 17:09:27

Maybe look at IInstalledExtension.InstallPath. You can get an IInstalledExtension via an IVsExtensionManager.

Unfortunately, the message in the remarks suggests this is not the right way to do things:

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;
    }

The string identifier is whatever you put in the "ID" field of your extension's source.extension.vsixmanifest file. It defaults to the package GUID.

Hazza

Sorry for digging up an old answered question...

I was looking into a similar problem, and have implemented the Extension Manager, but decided this is just pretty awful, though if you do want to do use it these links will also help:

https://stackoverflow.com/a/24294185

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

However, I decided to look into how the CodeGenerator in Asp.Net.Scaffolding accessed template files. Turns out, very easily...

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

Simples

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!