Share via


How to create a pkgdef file for your Visual Studio Package

The .pkgdef file was first introduced with VS 2008, to allow for easily registering packages targeting the VS 2008 isolated shell. Bill Wienberger details the rationale behind this change in the following blog entry: What’s A PkgDef? And Why?

There are a couple of ways .pkgdef files can be created. For a managed package, the .pkgdef file can be built using the RegPkg.exe utility with the /pkgdeffile switch. The RegPkg.exe utility will read and execute the various registration attributes in the package assembly to construct the pkgdef file. If the package project was initially created with the VS SDK 1.1 (or later) project wizard, build rules were automatically added to the project file that will automatically generate the .pkgdef during your build operation. For example, you may have noticed something similar to the following in the build output window after building your managed package:

C:\Program Files\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Tools\bin\RegPkg.exe /root:Software\Microsoft\VisualStudio\9.0Exp "/pkgdeffile:obj\Debug\VS08ManagedPackage.pkgdef" "C:\Users\<user>\Documents\Visual Studio 2008\Projects\VS08ManagedPackage\VS08ManagedPackage\bin\Debug\VS08ManagedPackage.dll"

Or possibly if you’re using VS 2010:

GeneratePkgDef:
   Creating intermediate PkgDef file.
      C:\Program Files\Microsoft Visual Studio 2010 SDK\VisualStudioIntegration\Tools\bin\CreatePkgDef.exe /out="obj\Debug\My2010Package.latest.pkgdef" /codebase … "c:\users\<user>\documents\visual studio 2010\Projects\My2010Package\My2010Package\bin\Debug\My2010Package.dll"
   Copying file from "obj\Debug\My2010Package.latest.pkgdef" to "obj\Debug\My2010Package.pkgdef".
   CopyPkgDef:
      Copying file from "obj\Debug\My2010Package.pkgdef" to "bin\Debug\My2010Package.pkgdef".

Creating a .pkgdef for C++ based packages requires a bit more work, as the C++ project system (in VS 2008) was not based on MSBuild. If your native C++ package was originally created with VS 2008 SDK 1.1 (or later) project wizard, an initial .pkgdef file was automatically included with your project. This default .pkgdef will contain the settings/tokens based on the initial settings you specified in the project wizard. Additional entries, or changes to the existing .pkgdef must be done manually, as we cannot leverage the RegPkg.exe utility.

A list of the various replacement tokens that can be used in a .pkgdef file can currently be found in the following help topic: Isolated Shell Extension Points. The topic title is a little out of date, but the tokens listed are entirely valid for packages targeting either the isolated or integrated shells.

Tips for creating a pkgdef file (if you don’t already have one):

  • If your package is a managed package that targets VS 2005, use RegPkg.exe to create a .reg or .vrg file for guidance to find the registry keys and values you’ll need to include for your package.
  • If your package is a C++ based package, review your installer and note the various registry keys and values it creates/adds.
  • Create and build a test package using the VS 2008/2010 SDK. And use the generated pkgdef as a template.