IVsSettingsWriter Interface
Assembly: Microsoft.VisualStudio.Shell.Interop.8.0 (in microsoft.visualstudio.shell.interop.8.0.dll)
This interface is implemented by the environment.
Notes for Callers
Call IVsSettingsWriter when storing a VSPackage's configuration information into the Visual Studio settings file.
Notes for Implementers
Only VSPackages that have registered their support for the Visual Studio settings mechanism make use of IVsSettingsWriter. For more information on registering a VSPackage as supporting the Visual Studio settings mechanism, see Persisting Settings.
When a setting export operation has been selected from the Import/Export Settings feature available on the IDE’s Tools menu, the environment passes a IVsSettingsWriter interface to a VSPackage's settings export method, which uses the interface to write out configuration data. The Visual Studio SDK supports several export methods:
-
For interop assembly based VSPackages, the export method is the VSPackage's implementation of the IVsUserSettings interface's ExportSettings.
-
For most Managed Package Framework based VSPackages, the export method is the VSPackage's implementation of the IProfileManager interface's SaveSettingsToXml.
-
For Managed Package Framework based VSPackages implementing the DialogPage interface, the export method is that interface's SaveSettingsToXml.
For more information, see How to: Export Settings by Using Interop Assemblies or How to: Export Settings by Using the Managed Package Framework.
Note |
|---|
| In addition to any data stored by using IVsSettingsWriter methods, the IDE always transparently stores the version of Visual Studio used to export configuration data. |
Note |
|---|
| Best practice when storing buffers or string is to save the size of the stored buffer or string as well as with the object itself. This size information should always be used when retrieving the saved buffer of string to avoid buffer overruns. |
In the example below is a method called by an implementation of ExportSettings, the method writes out three settings values, one of which is the size of a buffer to be stored.
HRESULT ExportSettings_CommandBars(IVsSettingsWriter *pSettings)
{
if (!pSettings)
return E_INVALIDARG;
hr = pSettings->WriteSettingString(c_szFirstSettingName, L"Value1");
IfFailGo(hr);
int cRandomTrash = 12345;
BYTE *pRandomTrash = (BYTE *)VSAlloc(cRandomTrash);
if (pRandomTrash){
hr = pSettings->WriteSettingBytes(c_szRandomTrashBytes, pRandomTrash, cRandomTrash);
IfFailGo(hr);
hr = pSettings->WriteSettingLong(c_szRandomTrashLength, cRandomTrash);
IfFailGo(hr);
}
Error:
return hr;
};
Tasks
How to: Export Settings by Using Interop AssembliesHow to: Export Settings by Using the Managed Package Framework
Reference
IVsSettingsWriter MembersMicrosoft.VisualStudio.Shell.Interop Namespace
IVsSettingsReader Interface
ExportSettings
Note