IVsExtensionManager.GetEnabledExtensionContentLocations 方法 (String, IDictionary<String, String>)

特定类型的所有目录路径的集合的查询在已启用的扩展中,通过与给定属性来筛选结果到内容节点的 XML 属性。

命名空间:  Microsoft.VisualStudio.ExtensionManager
程序集:  Microsoft.VisualStudio.ExtensionManager(在 Microsoft.VisualStudio.ExtensionManager.dll 中)

语法

声明
Function GetEnabledExtensionContentLocations ( _
    contentTypeName As String, _
    attributes As IDictionary(Of String, String) _
) As IEnumerable(Of String)
IEnumerable<string> GetEnabledExtensionContentLocations(
    string contentTypeName,
    IDictionary<string, string> attributes
)
IEnumerable<String^>^ GetEnabledExtensionContentLocations(
    String^ contentTypeName, 
    IDictionary<String^, String^>^ attributes
)
abstract GetEnabledExtensionContentLocations : 
        contentTypeName:string * 
        attributes:IDictionary<string, string> -> IEnumerable<string> 
function GetEnabledExtensionContentLocations(
    contentTypeName : String, 
    attributes : IDictionary<String, String>
) : IEnumerable<String>

参数

  • contentTypeName
    类型:String

    筛选要搜索的内容类型。

  • attributes
    类型:IDictionary<String, String>

    目录的属性要匹配的。

返回值

类型:IEnumerable<String>
contentTypeName 对应于 VSIX 内容 元素的子级清单为扩展扩展路径的集合和 attributes 与该子元素 XML 属性。

备注

尽管此 API 支持 扩展管理器 基础结构,不建议使用它,因为它可能会发生更改。

示例

下面的示例使用 GetEnabledExtensionContentLocations 获取特定自定义类型的所有扩展的位置。 然后使用 CreateExtension 访问其他元数据对每个扩展中的和获取其名称。 在将保存名称和路径信息后,它会为每个扩展的菜单命令。

// This is the CommandID of the placeholder menu item,  
// as defined in the .vsct file. 
int CmdIdBase = 0x103;

// These lists will store name and path information. 
private ArrayList SkinNames = new ArrayList();
private ArrayList SkinPaths = new ArrayList();

// Call this from Initialize(). 
private void InitSkinList()
{
    var mcs = GetService(typeof(IMenuCommandService)) 
        as OleMenuCommandService;
    int counter = CmdIdBase;

    // Get the Extension Manager service. 
    var ExtMgrSvc = GetService(typeof(SVsExtensionManager)) 
        as IVsExtensionManager;

    // Iterate through installed extensions. 
    var attributes = new Dictionary<string, string>();
    attributes.Add("Type", "Skin");
    foreach (string SkinPath
        in ExtMgrSvc.GetEnabledExtensionContentLocations(
        "CustomExtension", attributes))
    {
        // Store the name and path information.
        SkinPaths.Add(SkinPath);
        SkinNames.Add(ExtMgrSvc.CreateExtension(SkinPath).Header.Name);

        // Create a CommandID for the new menu item. 
        var cmdID = new CommandID(
            GuidList.guidVSSkinHostCmdSet, counter);

        // Create the menu item and add its event handlers. 
        var mc = new OleMenuCommand(
            new EventHandler(OnSkinExec), cmdID);
        mc.BeforeQueryStatus += new EventHandler(OnSkinQueryStatus);
        mcs.AddCommand(mc);

        counter ++;
    }
}

private void OnSkinQueryStatus(object sender, EventArgs e)
{
    var menuCommand = sender as OleMenuCommand;
    if (null != menuCommand)
    {
        // Determine which menu item was queried. 
        int skinIndex = menuCommand.CommandID.ID - this.CmdIdBase;
        if (skinIndex >= 0 && skinIndex < this.SkinNames.Count)
        {
            // Set the text.
            menuCommand.Text = this.SkinNames[skinIndex] as string;
        }
    }
}

private void OnSkinExec(object sender, EventArgs e)
{
    var menuCommand = sender as OleMenuCommand;
    if (null != menuCommand)
    {
        // Get the name of the skin from the menu item. 
        string skinName = menuCommand.Text;

        // Locate the name in the list of skins.  
        int i = this.SkinNames.IndexOf(skinName);

        // Get the corrsponding path. 
        var skinPath = SkinPaths[i] as string;

        if (SkinNames.Count > 0)
        {         
            if (File.Exists(skinPath) || Directory.Exists(skinPath))
            {
                // Put code here to apply the skin extension...
                MessageBox.Show("Skin " + skinName + " found:\r\n" 
                    + skinPath + ". \r\n\r\nApplying skin...");
            }
           else MessageBox.Show("Could not find skin " + skinName);
        }
    }
}

.NET Framework 安全性

请参阅

参考

IVsExtensionManager 接口

GetEnabledExtensionContentLocations 重载

Microsoft.VisualStudio.ExtensionManager 命名空间