SettingsManager.GetWritableSettingsStore available for import/export in Visual Studio Extension?
Asked Answered
T

1

12

I'm using the SettingsManager in my Visual Studio extension to store user settings.

SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
var store = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

I have a custom WPF Options page, as described in this post. I'd also like to set my extension up to work with the Import/Export settings, so I followed the Creating an Options Page and Creating a Settings Category pages, to add this to my package attributes:

[ProvideProfile(typeof(OptionsDialogPage), "Unit Test Boilerplate Generator", "Unit Test Boilerplate Generator Settings", 106, 107, true, DescriptionResourceID = 108)]
[ProvideOptionPage(typeof(OptionsDialogPage), "Unit Test Boilerplate Generator", "Templates", 101, 109, supportsAutomation: true)]

I successfully got it to appear as a heading under Import/Export settings, but none of my data stored with the SettingsManager shows up after the export. I was looking over the options under ProvideProfile and ProvideOptionPage and tried setting SupportsProfiles = true but that didn't help.

How do I hook the two of these systems up?

(edit) I ran Process Monitor and found the SettingsManager keys here (CollectionPath UnitTestBoilerplateGenerator):

\REGISTRY\A\{08894cfc-f3a9-f49b-133e-3453dfe7a27d}\Software\Microsoft\VisualStudio\15.0_a703f143Exp\UnitTestBoilerplateGenerator\Template_VisualStudio_Moq_File

And the built-in options stored here (example from another extension):

\REGISTRY\A\{22e40365-b8e3-e9b2-1315-55021a1e4c3d}\Software\Microsoft\VisualStudio\15.0_a703f143\ApplicationPrivateSettings\Xavalon\XamlStyler\Core\Options\StylerOptions\NoNewLineElement

So it seems like they get stored in separate areas. Is there any way to write programmatically to those built-in options or to include the custom CollectionPath in the import/export?

Tomy answered 25/9, 2017 at 2:52 Comment(4)
Do you have tried ExternalSettingsManager(msdn.microsoft.com/en-us/library/…)? By using this class, you can search for properties and collections in different scopes. It contains references to the SettingsStore class and the WritableSettingsStore class for further manipulation of the properties and collections in the scopes.Crewel
@Wendy-MSFT It looks like this is what you use when you have a separate application shell. What method would you call to get to settings that are backed up by Import/Export?Tomy
GetReadOnlySettingsStore provides the SettingsStore class for the requested scope which can be used for read-only operations and GetWritableSettingsStore provides the WritableSettingsStore class for the requested scope which can be used for reading operations and writing operations. We could use both of these method to get all readonly and writable settings.Crewel
@Wendy-MSFT I know how to use the SettingsStore and I'm already calling GetWritableSettingsStore. My problem is that when I use it, the settings don't get backed up when I export my extension's settings.Tomy
T
0

I found a way to do it. You need to write to a collection path corresponding to the full type name of your options dialog type. Mine was UnitTestBoilerplate.View.OptionsDialogPage so I used a collection path of ApplicationPrivateSettings\UnitTestBoilerplate\View\OptionsDialogPage . I also needed to make a dummy property on the options dialog type to fool VS into actually exporting the setting. So if I was writing to MyProperty I needed

public int MyProperty { get; set; }

on OptionsDialogPage.

However this seems like a huge hack that might break on a new version of VS. I'd love a more elegant solution if anyone has one.

Also one really odd caveat is that if you have "VisualStudio" in the key name for a string setting, it comes back as "1*null*" no matter what you add there.

Tomy answered 5/10, 2017 at 3:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.