Partager via


Adding Command-Line Switches

Visual Studio SDK implementers might add command-line switches that apply to their VSPackages when devenv.exe is executed. The switches and their associated data must be added to the registry. By using the following code, you can add the switches via pkgdef:

[$RootKey$\AppCommandLine\<MySwitch>]

The MySwitch key can take four values as shown in the following table

Name

Type

Range

Description

Arguments

REG_SZ

>= 0 and *

Number of arguments that follow the switch.

DemandLoad

REG_DWORD

0x00000000 or 0x00000001

Load VSPackage if switch is present.

HelpString

REG_SZ

Not applicable

Resource ID of string to display with devenv /?.

Package

REG_SZ

Not applicable

GUID of VSPackage.

The first value of Arguments is usually 0 or 1. A special value of '*' can be used to indicate that the entire remainder of the command line is the argument. This can be useful for debugging scenarios where a user must pass in a debugger command string.

The DemandLoad value specifies a true (1) or false (0) indication that the integrated development environment (IDE) should force load your package. This is another of the IDE's delayed loading schemes.

The HelpString value is the resource ID of the string that appears in the devenv /?Help display. This value should be in the form "#nnn" where nnn is an integer. The string value in the resource file should end in a new line character.

The Package value is the GUID of the package that implements this switch. The IDE uses this GUID to find the VSPackage in the registry to which the command-line switch applies.

Retrieving Command-Line Switches

When your package is loaded, you can retrieve the command-line switches by completing the following steps.

  1. In your VSPackage's SetSite implementation, call QueryService on SVsAppCommandLine to get the IVsAppCommandLine interface.

  2. Call GetOption to retrieve the command-line switches that the user entered.

It is your responsibility to check for your command-line switches each time your package is loaded.

See Also

Reference

Devenv Command Line Switches

CreatePkgDef Utility

IVsAppCommandLine

SetSite

Concepts

Modifying the Isolated Shell By Using the .Pkgdef File