views:

113

answers:

1

In a Windows Service project, with a Project Installer I tried the following:

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();
    }

    protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
    {
        base.OnBeforeInstall(savedState);
        Settings.Default.ASetting = "aValue";
        Settings.Default.Save();
    }

    protected override void OnAfterInstall(System.Collections.IDictionary savedState)
    {
        base.OnAfterInstall(savedState);
        Settings.Default.ASetting = "aValue";
        Settings.Default.Save();
    }
}

But after the installation when I check the .config file, a older value is still there. There was no .config file in the usual [userfolder]\AppData\Local

For me is important to define this variable in installation time since I will receive its value from a user input in the Setup Project. The constant value here is used for testing purposes only.

+1  A: 

The framework will not allow you to change the settings while installing, since Application settings are read-only and there is no user context until the service is installed and running (under a username).

The only solution I have found is to change the settings using plain XML manipulation of the config file. I override the Install method and make changes to the file itself.

Charlie Brown
I'd rather write to the Windows registry than do as you say. Unless I find a working code to copy/paste.
Jader Dias