c# - SettingsManager.GetWritableSettingsStore 可用于在 Visual Studio 扩展中导入/导出?

标签 c# visual-studio-2017 visual-studio-extensions

我在我的 Visual Studio 扩展中使用 SettingsManager 来存储用户设置。

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

我有一个自定义 WPF 选项页面,as described in this post .我还想将我的扩展设置为使用导入/导出设置,所以我遵循了 Creating an Options PageCreating a Settings Category页面,将其添加到我的包属性中:

[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)]

我成功地将其显示为导入/导出设置下的标题,但在导出后,我使用 SettingsManager 存储的所有数据均未显示。我正在查看 ProvideProfileProvideOptionPage 下的选项并尝试设置 SupportsProfiles = true 但这没有帮助。

如何连接这两个系统?

(编辑)我运行 Process Monitor 并在此处找到 SettingsManager 键(CollectionPath UnitTestBoilerplateGenerator):

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

以及存储在这里的内置选项(来自另一个扩展的示例):

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

所以它们似乎存储在不同的区域。有没有办法以编程方式写入这些内置选项或在导入/导出中包含自定义 CollectionPath?

最佳答案

我找到了一种方法。您需要写入与选项对话框类型的完整类型名称相对应的集合路径。我的是 UnitTestBoilerplate.View.OptionsDialogPage 所以我使用了 ApplicationPrivateSettings\UnitTestBoilerplate\View\OptionsDialogPage 的集合路径。我还需要在选项对话框类型上创建一个虚拟属性,以欺骗 VS 实际导出设置。所以如果我写信给 MyProperty 我需要

public int MyProperty { get; set; }

在 OptionsDialogPage 上。

然而,这似乎是一个巨大的 hack,可能会破坏新版本的 VS。如果有人有的话,我会喜欢一个更优雅的解决方案。

还有一个非常奇怪的警告是,如果您在字符串设置的键名中有“VisualStudio”,无论您在其中添加什么,它都会返回“1*null*”。

关于c# - SettingsManager.GetWritableSettingsStore 可用于在 Visual Studio 扩展中导入/导出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46396956/

相关文章:

visual-studio-2017 - .editorconfig 在 VS2017 中没有做任何事情?

c++ - 如何在 VS 2017 中为 C++ 添加单元测试?

visual-studio-extensions - Visual Studio SDK - 如何在调用的命令上添加边距字形?

visual-studio-2010 - 即使不存在 using 语句,Visual Studio 2010 扩展也会向智能感知添加扩展方法

c# - 当目标文件已经存在时,如何使用 WinSCP .NET Assembly 移动/重命名文件?

c# - 无法从 'MongoDB.Driver.IMongoCollection<>' 转换为 'System.Collections.Generic.IEnumerable<>'

c# - 使用 C# 查找具有路径和 id 属性值的单个节点

c# - 启动命令行,包括来自 C# 的参数

xamarin.forms - 无法在 Visual Studio 的 Storyboard编辑器中添加图像来为 Xamarin.iOS 创建启动屏幕

git - Visual Studio 扩展未知错误 - 无法推送或获取任何内容