Partager via


How to: Create Menu Commands for a VSPackage By Using the Binary Command Table Compiler

Notes

Beginning with Visual Studio 2008 SDK, use XML Command Table (.vsct) files instead of command table configuration (.ctc) files to define how menus and commands appear in your VSPackages. For more information, see XML-Based Command Table Configuration (.vsct) Files.

You add commands and menus to your VSPackage using a two-step process. First, you place them into a .ctc file and compile them into a binary command table output (.cto) file using the Binary Command Table Compiler. Then, you include the .cto file as a resource in the local native satellite DLL, managed satellite DLL, or in managed VSPackage code.

The following procedures are necessary only if you are not using the Visual Studio SDK wizards, because they automatically perform these tasks for you.

The first procedure demonstrates how to compile the menu commands for your VSPackage into a binary .cto file. The next procedure shows how to use this file to expose the new VSPackage menus and commands in the Visual Studio IDE.

To create menu commands for a VSPackage

  1. Create a command table .ctc file for the VSPackage as detailed in Designing Command Table Configuration Files.

  2. Compile the .ctc file using the Binary Command Table Compiler (Ctc.exe) to produce a binary .cto file.

    Ctc.exe is located in EnvSDK\tools\bin\x86 directory under the Visual Studio SDK installation path. The default path is C:\Program Files\VSIP <Version>\EnvSDK\tools\bin\x86, where <Version> is the version of the Visual Studio SDK release.

  3. Add the .cto file as a binary resource either to the managed VSPackage project, to a local native satellite DLL, or to a managed satellite DLL.

    To do this, add the .cto file as a custom resource named CTMENU to the VSPackage's resource (.rc) file and assign it a unique ID. All of the menu and toolbar samples (listed in the Samples folder under Menu and Toolbar Commands folder in the table of contents) use this method. For more information about this, see Registering Interop Assemblies Command Handlers.

To expose the new VSPackage menus and commands in the IDE

  1. Install your VSPackage in Visual Studio.

  2. Register the VSPackage using Regpkg.exe as detailed in Registering VSPackages.

    This places a registry key named CLSIDofPackage in the [HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\<version>\Menus] section.

    To avoid disrupting the existing IDE commands and menus with those of your package while you are debugging it, your VSPackage is registered in an alternate registry called the experimental hive. For more information about this, see Experimental Build.

    There are two possible values for CLSIDofPackage:

    • <blank space>, 1000, 10

    • <drive>:\VisualStudio\bin\MyPackage.dll, 1000, 10

    The data field for CLSIDofPackage is split into three sections separated by commas.

    First Section: The full path name to the .cto file. If you leave this field blank, which is the recommended method, then the environment searches for the .cto information in your VSPackage's satellite DLL, as specified under the VSPackages section in the registry. If you need to, however, you can provide a specific path to the .cto file.

    Second Section: The resource number of the menus in the .cto file. This must be a number, not a name or identifier.

    Third Section: The version of the menu resource. Increment this number as you update the menus. Visual Studio will detect the version number change and re-merge the menus.

  3. Implement handlers for the new commands. For information on doing this, see Commands and Menus That Use Interop Assemblies.

    At a command prompt, enter devenv /setup to cause Visual Studio to merge the new VSPackage menus and commands with those already in Visual Studio.

Robust Programming

The first procedure on this page outlines how to manually run Ctc.exe to create the .cto file. But when normally creating VSPackages, it is easier to instead run Ctc.exe by configuring a custom build step in Visual Studio. The Visual Studio SDK wizards do this for you. This eliminates the manual compilation step.

When you uninstall a VSPackage, the uninstaller removes the CLSIDofPackage registry key. Running devenv /setup then removes the menus from the IDE. The

Visual Studio SDK features resource registration by modifying the class that defines your managed VSPackage with registration attributes like ProvideMenuResourceAttribute and ProvideKeyBindingTableAttribute. When you execute Regpkg.exe, resource registry locations are extracted through reflection and are written to the registry. While the creation of the registration attribute classes has made registering VSPackage resources much easier, the underlying registry-based implementation remains unchanged.

Ctc.exe reads only multi-byte character set (MBCS) encoded files which it then converts to Unicode using the codepage of the current console. It will not read files saved as Unicode. Keywords are case-sensitive, must be ASCII, and must match the documentation exactly. The entire .cto file must be copied and localized.

The devenv.exe /setup command merges the new VSPackage's menus and commands into a user-specific initialization file called <user profile path>\Application Data\Microsoft\VisualStudio\<version>\<loc>\devenv.ctm. Additional customizations, such as the position of toolbars, are stored in a user profile file called <user profile path>\Application Data\Microsoft\VisualStudio\<version>\<loc>\cmdUI.PRF.

In the above paths, <user profile path> is a user's home directory, such as C:\Documents and Settings\MyLogin. <version> is the version of Visual Studio, and <loc> is the localization subdirectory (for U.S. English, this is 1033).

See Also

Concepts

Designing Command Table Configuration Files

Command Table Format Reference

Common Menu Tasks

How to: Create Menu Commands for a VSPackage By Using the Binary Command Table Compiler

Installing VSPackages with Windows Installer

Command-Line Switches (Visual Studio SDK)