Skip to content

Latest commit

 

History

History
69 lines (51 loc) · 3.56 KB

adding-command-line-switches.md

File metadata and controls

69 lines (51 loc) · 3.56 KB
titledescriptionms.datems.topichelpviewer_keywordsauthorms.authormanagerms.subservice
Adding Command-Line Switches
Learn how to add command-line switches that are applied to a VSPackage when the devenv.exe command is executed.
11/04/2016
how-to
command-line switches, adding
command-line switches, retrieving
IVsAppCommandLine::GetOption method
command line, switches
maiak
maiak
mijacobs
extensibility-integration

Add command-line switches

You can add command-line switches that apply to your VSPackage when devenv.exe is executed. Use xref:Microsoft.VisualStudio.Shell.ProvideAppCommandLineAttribute to declare the name of the switch and its properties. In this example, the MySwitch switch is added for a subclass of VSPackage named AddCommandSwitchPackage with no arguments and with the VSPackage loaded automatically.

[ProvideAppCommandLine("MySwitch",typeof(AddCommandSwitchPackage),Arguments="0",DemandLoad=1)]

The named parameters are shown in the following descriptions.

NameDescription
ArgumentsThe number of arguments for the switch. Can be "*", or a list of arguments.
DemandLoadLoad the VSPackage automatically if this is set to 1, otherwise set to 0.
HelpStringThe help string or resource ID of the string to display with devenv /?.
NameThe switch.
PackageGuidThe GUID of the package.

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 is either true (1) or false (0) indicates that the VSPackage should be loaded automatically.

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 Name value is the name of the switch.

The PackageGuid 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.

Retrieve 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 xref:Microsoft.VisualStudio.Shell.Interop.IVsPackage.SetSite%2A implementation, call QueryService on xref:Microsoft.VisualStudio.Shell.Interop.SVsAppCommandLine to get the xref:Microsoft.VisualStudio.Shell.Interop.IVsAppCommandLine interface.

  2. Call xref:Microsoft.VisualStudio.Shell.Interop.IVsAppCommandLine.GetOption%2A to retrieve the command-line switches that the user entered.

    The following code shows how to find out whether the MySwitch command-line switch was entered by the user:

IVsAppCommandLinecmdline=(IVsAppCommandLine)GetService(typeof(SVsAppCommandLine));intisPresent=0;stringoptionValue="";cmdline.GetOption("MySwitch",outisPresent,outoptionValue);

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

Related content

close