Compartilhar via


Support for Settings Categories

A settings category consists of a group of options that customize the integrated development environment (IDE). For example, settings can control the layout of Visual Studio windows and the contents of menus. For more information, see Customizing Development Settings in Visual Studio.

On the Tools menu click Import and Export Settings to start the Import and Export Settings Wizard. The wizard offers three choices: export, import, or reset your settings. Selecting export, for example, opens the Choose Settings to Export page of the wizard.

The tree control in the navigation pane of this page lists categories. A category is a group of related settings which appear as a "custom settings point", that is, as a check box. You use these check boxes to select the categories to persist in a .vsettings file. The wizard lets you name the .vsettings file and specify its path.

Note

Settings are saved or restored as a category, and individual setting names are not displayed in the wizard.

The managed package framework (MPF) supports creating settings categories with a minimum of additional code.

  • You create a VSPackage to provide a container for the category by subclassing the Package class.

  • You create the category itself by deriving it from the DialogPage class.

  • You connect the two with the ProvideProfileAttribute.

Support for Settings Categories

The Package class provides support for creating categories. The DialogPage class implements a category. The default implementation of DialogPage offers its public properties to a user as a category. For more information, see Walkthrough: Creating a Settings Category.

The DialogPage class implements IProfileManager, which provides persistence for both options pages and user settings. The LoadSettingsFromXml and SaveSettingsToXml methods persist settings into a .vssettings file that Visual Studio provides as an IVsSettingsReader or IVsSettingsWriter, respectively. The ResetSettings method resets settings to their default values.

The DialogPage class provides an implementation of the LoadSettingsFromXml method that reads name-value pairs from the xml feed, and uses reflection to discover public properties in the DialogPage derived class. Properties that have names that match the name-value pairs are given the corresponding values.

The default implementation of SaveSettingsToXml uses reflection to discover public properties in the DialogPage derived class and writes the property names and values to the XML feed as name-value pairs.

Settings Category Registry Path

The registry path of the settings category is determined by combining ApplicationRegistryRoot, the word, UserSettings, the settings category, and the name of the custom settings point. The names of the settings category and custom settings point are joined and separated by an underscore to form the canonical, non-localized name that appears in the registry. For example, if the settings category is "My Category", the custom settings point name "My Settings", and the ApplicationRegistryRoot HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp, then the settings category has the registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp\UserSettings\My Category_My Settings.

Note

The canonical name does not appear in a user interface (UI). It is used to associate a readable name with the settings category, much like a programmatic identifier (ProgID).

Settings Category Attribute

The ProvideProfileAttribute determines the mapping of categories to custom settings points in the Import and Export Settings Wizard by associating a category with the VSPackage that provides it. Consider the following code fragment:

<ProvideProfile(GetType(OptionsPageGeneral), "My Category", "My Settings", 106, 107, True, DescriptionResourceID:=108),
 Guid("B0002DC2-56EE-4931-93F7-70D6E9863940")>
Public Class MyPackage
    Inherits Package
[ProvideProfile(typeof(OptionsPageGeneral),"My Category", "My Settings", 106, 107, true, DescriptionResourceID = 108)]
[Guid("B0002DC2-56EE-4931-93F7-70D6E9863940")]
public class MyPackage : Package

Resource ID 106 maps to "My Category", 107 to "My Settings", and 108 to "Various Options". This declares that MyPackage provides the category, My Category_My Settings. The category is provided by the OptionsPageGeneral class, which must implement IProfileManager. The settings in that category are the public properties of the OptionsPageGeneral class.

In the Import and Export Settings Wizard, the settings point has the name, My Settings. When the settings point is selected, the description, Various Options, appears. The settings point name and description are taken from localized string resources.

See Also

Tasks

Walkthrough: Creating an Options Page

Concepts

Visual Studio Extensibility Samples

Customizing Development Settings in Visual Studio

Other Resources

VSPackage State