I have created a Windows service which is installed via an MSI. The service requires a host/IP, port, and path to communicate with which I have added as separate properties in VS2017 Settings.settings. I now want to have the installer take user input and write the settings to my config file. To begin with, I tried the following:
public override void Install(IDictionary stateSaver)
{
string server;
string port;
string path;
base.Install(stateSaver);
server = this.Context.Parameters["SERVER"];
port = this.Context.Parameters["PORT"];
path = this.Context.Parameters["PATH"];
Properties.Settings.Default.server = server;
Properties.Settings.Default.port = port;
Properties.Settings.Default.path = path;
Properties.Settings.Default.Save();
}
And an extract from my app.config file...
<userSettings>
<myService.Properties.Settings>
<setting name="server" serializeAs="String">
<value />
</setting>
<setting name="port" serializeAs="String">
<value />
</setting>
<setting name="path" serializeAs="String">
<value />
</setting>
</myService.Properties.Settings>
</userSettings>
This doesn't save the settings, so I resorted to Google. The closest thing I have found is this question, however I don't fully understand what it's suggesting (I'm pretty new to C#). Am I using a full ServiceModel section group? I'm sure I could figure out how to edit the XML directly but that would be a bodge and not the proper way, I'd rather do it right.