How to: Register a VSPackage (C#)

The managed package framework (MPF) provides attributes to control the registration of managed VSPackages. The RegPkg utility uses these attributes to register a VSPackage for development. By default, Regpkg is located at <Visual Studio SDK installation path>\VisualStudioIntegration\Tools\Bin.

To obtain syntax and parameter information, run RegPkg with the /? switch.

Note

The Visual Studio 2008 Integration Package Wizard creates a VSPackage that is correctly registered to run in Visual Studio 2008. For more information on creating VSPackages, see How to: Create VSPackages (C# and Visual Basic).

Example

The code that follows is from the Reference.Package (C#) sample.

The DefaultRegistryRootAttribute attribute sets the default registration to the experimental root, typically located at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp.

The PackageRegistrationAttribute registers the VSPackage with Visual Studio 2008 under the Packages key of that root, that is, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0Exp\Packages.

Robust Programming

Any package that contains managed ctc resources must run the RegPkg utility with the /codebase switch for the bitmaps associated with the package, such as menu and toolbar icons, to appear.

RegPkg /codebase MyPackage.dll

The DefaultRegistryRootAttribute attribute sets the default registry root. The actual registry root is determined by the /root argument of the RegPkg.exe command-line utility, which is run as part of the build process. If the /root argument is not given, RegPkg uses the default registry root instead.

The experimental registry root is used for VSPackage development. This root is passed to RegPkg from the <TargetRegistryRoot> tag in the .csproj project file and overrides the default root. RegPkg effectively runs as follows:

RegPkg /root: Software\Microsoft\VisualStudio\9.0Exp MyPackage.dll

After development, VSPackages can be installed on computers that have no Visual Studio SDK. The RegPkg utility is not redistributable, but RegPkg can be used to generate a registration manifest for a managed VSPackage. This manifest can be incorporated into an MSI installer. For more information, see How to: Generate Registry Information for an Installer (C#).

See Also

Other Resources

Registering VSPackages

VSPackages