Getting Service Information from the Settings Store
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
You can use the settings store to find all available services or to determine whether a particular service is installed. You must know the type of the service class.
To list the available services
Create a VSIX project named FindServicesExtension and then add a custom command named FindServicesCommand. For more information about how to create a custom command, see Creating an Extension with a Menu Command
In FindServicesCommand.cs, add the following using statements:
using System.Collections.Generic; using Microsoft.VisualStudio.Settings; using Microsoft.VisualStudio.Shell.Settings; using System.Windows.Forms;
Get the configuration settings store, then find the subcollection named Services. This collection includes all the available services. In the MenuItemCommand method, remove the existing code and replace it with the following:
private void MenuItemCallback(object sender, EventArgs e) { SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider); SettingsStore configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration); string message = "Available services:\n"; IEnumerable<string> collection = configurationSettingsStore.GetSubCollectionNames("Services"); int n = 0; foreach (string service in collection) { message += configurationSettingsStore.GetString("Services\\" + service, "Name", "Unknown") + "\n"; } MessageBox.Show(message); }
Build the project and start debugging. The experimental instance appears.
In the experimental instance, on the Tools menu, click Invoke FindServicesCommand.
You should see a message box listing all the services.
To verify these settings, you can use the registry editor.
Finding a Specific Service
You can also use the CollectionExists method to determine whether a particular service is installed. You must know the type of the service class.
In the MenuItemCallback of the project you created in the previous procedure, search the configuration settings store for the
Services
collection that has the subcollection named by the GUID of the service. In this case we will look for the Help service.private void MenuItemCallback(object sender, EventArgs e) { SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider); SettingsStore configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration); string helpServiceGUID = typeof(SVsHelpService).GUID.ToString("B").ToUpper(); bool hasHelpService = configurationSettingsStore.CollectionExists("Services\\" + helpServiceGUID); string message = "Help Service Available: " + hasHelpService; MessageBox.Show(message); }
Build the project and start debugging.
In the experimental instance, on the Tools menu, click Invoke FindServicesCommand.
You should see a message with the text Help Service Available: followed by True or False. To verify this setting, you can use a registry editor, as shown in the earlier steps.