IVsExtensionManager.GetEnabledExtensionContentLocations Method (String, IDictionary<String, String>)


Queries for a collection of the paths of all content of a particular type that is included in enabled extensions, and then filters the results by matching the given attributes to the XML attributes on the content node.

Namespace:   Microsoft.VisualStudio.ExtensionManager
Assembly:  Microsoft.VisualStudio.ExtensionManager (in Microsoft.VisualStudio.ExtensionManager.dll)

IEnumerable<string> GetEnabledExtensionContentLocations(
	string contentTypeName,
	IDictionary<stringstring> attributes


Type: System.String

The content type to filter the search by.

Type: System.Collections.Generic.IDictionary<StringString>

The attributes of the content to match.

Return Value

Type: System.Collections.Generic.IEnumerable<String>

A collection of paths of extensions where contentTypeName corresponds to a child of the element of the VSIX manifest for the extension, and attributes match the XML attributes of that child element.

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

The following example uses GetEnabledExtensionContentLocations to get the locations of all extensions of a particular custom type. It then uses CreateExtension to access the other metadata for every extension found and get its name. After it saves the names and path information, it creates menu commands for each extension.

// 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.

        // 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);

        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);
Return to top