Visual Studio加载项应在哪里存储其设置? [英] Where should a Visual Studio Add-in store its settings?

查看:140
本文介绍了Visual Studio加载项应在哪里存储其设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我将自定义加载项的设置存储在注册表中,但这似乎有点麻烦。我想知道是否有一个官方的位置来存储加载项设置。我的偏好是将它们存储在Visual Studio存储设置的位置,以便可以轻松导出和导入它们。

Currently I'm storing the settings for my custom addins in the registry but this seems like a kludge. I was wondering if there was an official place to store add-in settings. My preference would be to store them where Visual studio stores settings so they can be exported and imported easily.

是否可以使用Visual Studio设置存储加载项设置,还是有更好的方法?

Is it possible to store add-in settings with Visual Studio settings or is there a better way?

推荐答案

编辑

这个主题的最初答案是我使用多年后发现的几个问题它。为了完整起见,我将其包括在下面,但这是我对此的更新想法。

My original answer to this topic had a couple of issues I discovered after years of using it. I've included it below for completeness but here is my updated thoughts on this.

在VSIX中,应用程序设置的使用不是版本安全的。存储的设置文件路径的位置部分包括版本字符串和可执行文件的哈希。当Visual Studio安装正式更新时,这些值会更改,因此更改设置文件路径。 Visual Studio本身不支持使用应用程序设置,因此它不会尝试将该文件迁移到新位置,并且所有信息实际上都会丢失。
支持的设置方法是WritableSettingsStore。它与应用程序设置非常相似,并且很容易通过SVsServiceProvider进行访问

The use of application settings is not version safe in a VSIX. The location of the stored setting file path in part includes the version string and hashes of the executable. When Visual Studio installs an official update these values change and as a consequence change the setting file path. Visual Studio itself doesn't support the use of application settings hence it makes no attempt to migrate this file to the new location and all information is essentially lost. The supported method of settings is the WritableSettingsStore. It's very similar to application settings and easy enough to access via SVsServiceProvider

public static WritableSettingsStore GetWritableSettingsStore(this SVsServiceProvider vsServiceProvider)
{
    var shellSettingsManager = new ShellSettingsManager(vsServiceProvider);
    return shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
}

原始答案

最直接的方法是使用.Net的应用程序设置基础架构来存储任何设置。这是一个成熟的框架,具有设计者支持,可以为您的项目添加设置基础架构。

The most straight forward way is to use .Net's Application Settings infrastructure to store any settings. It's a mature framework with designer support for adding a settings infrastructure to your project.

但是它未与Visual Studio的导入/导出设置基础结构集成。使工作正常进行是一个非常复杂的过程,其中包括将您自己注册为VSPackage,实现设置架构等……我通常发现开始运行(从未成功)确实不值得麻烦

It however does not integrate with Visual Studio's Import / Export settings infrastructure. Getting that working is a very involved process that includes registering yourself as a VSPackage, implementing a settings schema, etc ... I generally find it's really not worth the trouble of getting running (never succeeded)

这篇关于Visual Studio加载项应在哪里存储其设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆