How to implement configuration data for a vsix ext

2019-08-01 09:39发布

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.

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.

Edit:

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.

2条回答
聊天终结者
2楼-- · 2019-08-01 10:00

Been there and in my opinion the built-in mechanism works best, detailed walkthrough: http://msdn.microsoft.com/en-us/library/ff460144.aspx

Adding a note from self I can see that the underlying implementation uses system registry subkey. However after VSIX extension uninstalled all the keys are removed automatically so your extension is not polluting the system leaving orphaned entries.

查看更多
【Aperson】
3楼-- · 2019-08-01 10:08

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

  • Right Click on the project and select "Properties"
  • Go to the Settings Tab
  • Click on the link to create a default settings file

This will create a couple of files in your solution.

  • Settings.settings
  • Settings.Designer.cs

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

查看更多
登录 后发表回答