How to implement configuration data for a vsix extension in Visual Studio 2010?

ε祈祈猫儿з 提交于 2019-12-11 09:55:30

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/6188231/how-to-implement-configuration-data-for-a-vsix-extension-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!