Listing Sited VSXtra Packages

This small package demonstrates how to enumerate VSXtra packages already sited in the Visual Studio IDE. The package also lists the registered command handler classes.

Points of Interest:

  • Everything uses declarative approach
  • Command handling requires only a simple method decorated with attributes.
  • CommandExecMethod signs that the method is to be executed as a response for a command.
  • The CommandId attribute defines how the command is bound to the method.
  • The PackageBase class contains a static property named SitedVSXtraPackages
  • The MenuCommandHandler class contains a static GetRegisteredHandlerInstances method to retrieve the registered method handler classes.

Package source code:

using System;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using VSXtra;

namespace DeepDiver.DisplayLoadedPackages
{
  [PackageRegistration(UseManagedResourcesOnly = true)]
  [DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\9.0")]
  [InstalledProductRegistration(false, "#110", "#112", "1.0", IconResourceID = 400)]
  [ProvideLoadKey("Standard", "1.0", "DisplayLoaded", "DeepDiver", 1)]
  [ProvideMenuResource(1000, 1)]
  [Guid(GuidList.guidDisplayLoadedPackagesPkgString)]
  public sealed class DisplaySitedPackages : PackageBase
  {
    [CommandExecMethod]
    [CommandId(GuidList.guidDisplayLoadedPackagesCmdSetString, CmdIDs.cmdidDisplayPackages)]
    private static void DisplayPackageInfo()
    {
      var sitedPackages = SitedVSXtraPackages;
      Console.WriteLine("There are currently {0} sited VSXtra packages:", sitedPackages.Count);
      foreach (var package in sitedPackages)
      {
        Console.WriteLine("  {0}", package.GetType().FullName);
        var registeredHandlers = MenuCommandHandler.GetRegisteredHandlerInstances(package.GetType());
        if (registeredHandlers.Count() > 0)
        {
          Console.WriteLine("    Registered command handlers:");
          foreach (var command in registeredHandlers)
          {
            Console.WriteLine("      {0}", command.GetType().FullName);
          }
        }
      }
    }
  }
}
Screenshots:

ListSitedPackages.png

Last edited Aug 28, 2008 at 12:13 PM by INovak, version 3

Comments

No comments yet.