Change userSettings during MSI installation

Posted by pagetailor on Stack Overflow See other posts from Stack Overflow or by pagetailor
Published on 2010-03-20T15:07:41Z Indexed on 2010/03/20 15:11 UTC
Read the original article Hit count: 415

Hi,

I am trying to modify the userSettings section (Properties.MyApp.Default) in the MyApp.exe.config file during the installation 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

    Properties.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!

© Stack Overflow or respective owner

Related posts about usersettings

Related posts about msi