Where should a Visual Studio Add-in store its settings?

前端 未结 2 851
我在风中等你
我在风中等你 2021-02-05 06:05

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. M

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 06:47

    EDIT

    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.

    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);
    }
    

    Original Answer

    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.

    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)

提交回复
热议问题