Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 367
RandomEngy Avatar asked Sep 25 '17 02:09

RandomEngy


People also ask

How do I export and import Visual Studio settings?

Actually, the Import and Export Settings feature(option) from Tools > Import and Export Settings… can help to export most of the Visual Studio 2019 configurations. You just need to select which settings you want to export by following the wizard.

Does Visual Studio have extensions?

Visual Studio MarketplacePersonalize your Visual Studio experience today by downloading extensions. Browse through thousands of extensions available in the Marketplace to find the tools you need. You can also publish your own extensions to the Marketplace.


1 Answers

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.

like image 169
RandomEngy Avatar answered Sep 28 '22 01:09

RandomEngy