开发者

Change userSettings during MSI installation

开发者 https://www.devze.com 2022-12-23 08:00 出处:网络
I am trying to modify the userSettings section (Properties.MyApp.Default) in the MyApp.exe.config file during the installatio of my WPF application using an MSI installer.

I am trying to modify the userSettings section (Properties.MyApp.Default) in the MyApp.exe.config file during the installatio of my WPF application using an MSI installer.

I basically implemented it like in this excellent article: http://raquila.com/software/configure-app-config-application-settings-during-msi-install/

The difference is that I am not editing the appSettings but the userSettings section.

The problem is that although the code runs fine, the settings are not saved. After the installation the config file contains the old settings I use in my development environment. I also tried to override OnAfterInstall(System.Collections.IDictionary stateSaver) instead of Install(System.Collections.IDictionary stateSaver) but it doesn't make a difference.

Here is the code that should change the config values:

protected override void OnAfterInstall(IDictionary savedState)
{
    base.OnAfterInstall(savedState);

    string targetDirectory = Context.Parameters["targetdir"];
    string tvdbAccountID = Context.Parameters["TVDBACCID"];
    // read other config elements...

    Properties.Settings.Default.Tvdb_AccountIdentifier = tvdbAccountID;
    // set other config elements

    Propert开发者_运维百科ies.Settings.Default.Save();
}

Any idea how to persist these changes? I already read about Wix but that seems like an overkill to me.

Thanks in advance!


User settings are saved in the current user's local folder, usually looks like C:\Users\Username\AppData\Local\Manufacturer\ApplicationName\Application.exe_StrongName\VersionNumber\user.settings Note that location changes with application versions.

UserSettings section of you exe.config contains default values for new users.

Check this question for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号