如何在 Visual Studio 2010 中实现 vsix 扩展的配置数据? [英] How to implement configuration data for a vsix extension in Visual Studio 2010?

查看:24
本文介绍了如何在 Visual Studio 2010 中实现 vsix 扩展的配置数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实现一个 vsix 扩展工具窗口,它将很快需要一个数据库连接字符串来查询一些数据,以便在工具窗口中向开发人员显示.我想让开发人员可以配置这个连接字符串.由于开发人员不太可能经常更改配置设置,因此一个文件就足够了.

I'm currently implementing a vsix extension tool window which will soon need a database connection string for querying some data to display to the developer in the tool window. I'd like to make this connection string configurable by the developer. As the developer is unlikely to change the config settings often a file would be sufficient.

是否可以只在与 sln 文件相同的文件夹中使用 app.config 文件,如果可以,我必须使用一些自定义配置设置来包装文件吗?NuGet 似乎实现了这种方法,但我不完全了解内部架构以了解如何使用配置文件.

Is it possible to just use an app.config file in the same folder as the sln file and if so must I use some custom configuration settings to wrap the file? NuGet seems to implement this approach but I don't fully understand the internal architecture to see how the config file is used.

我也很欣赏任何替代方法.

I'd appreciate any alternative approaches too.

此后我意识到配置存储将提供的动态数据必须特定于解决方案,以便一个解决方案中使用的工具窗口可以使用与另一个解决方案不同的属性.我想一种可能性是使用 .settings 文件来存储单个配置文件的位置,该文​​件本身存储与不同解决方案相关的信息.

I have since realised that the dynamic data the config store would serve must be solution specific so that a tool window used in one solution can use different properties to that of another solution. I guess one possibility would be to use the .settings file to store the location of a single config file that itself stores information related to different solutions.

推荐答案

存储 .vsix 扩展名设置的最佳位置是使用 .settings 文件.为了创建一个,请执行以下操作

The best place to store settings for a .vsix extension is to use a .settings file. In order to create one do the following

  • 右键单击项目并选择属性"
  • 转到设置"标签
  • 点击链接创建默认设置文件

这将在您的解决方案中创建几个文件.

This will create a couple of files in your solution.

  • 设置.settings
  • Settings.Designer.cs

此外,它会调出一个设计器,可以从中添加新设置.之后可以使用 Settings.Default 静态属性

Additionally it will bring up a designer from which new settings can be added. These can be accessed afterwards by using the Settings.Default static property

这篇关于如何在 Visual Studio 2010 中实现 vsix 扩展的配置数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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