I created a command-line application and moved a lot of its config into a standard Settings file. All settings are declared as Scope = Application, because there is nothing user-specific about the logic in the application. I access the values throughout the code with
Properties.Settings.Default.<whatever>
This works well as it runs automatically on a schedule. Updating values in the config file are reflected in the output.
Some time later, I created a basic GUI (in the same namespace) to launch the command-line application directly (through a separate constructor). I haven't done a huge amount of .Net programming, but I'm basically using my CLI application like a DLL (I don't know if there's a proper term for this; in my output folder, all I need is GUI.exe, CLI.exe and CLI.exe.config and it works). However, I've noticed that when launched this way, the CLI.exe.config file is not loaded; the CLI application uses only its compiled-in defaults. I was hoping the config file method would work in this instance.
I've tried the following methods to force loading the config file but so far have drawn a blank:
1:
ConfigurationManager.RefreshSection("appSettings")
2:
ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
configFile.ExeConfigFilename = Path.Combine(Environment.CurrentDirectory, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".exe.config");
ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None).Save(ConfigurationSaveMod.Modified);
ConfigurationManager.RefreshSection("appSettings");
3:
Properties.Settings.Default.Reload();
None of these produce errors, but the Properties.Settings.Default.Value
I have modified in the config file is not updated. Is there a way to accomplish what I need here?
Edit: here is a sample of my CLI.exe.config file if it helps illustrate what I'm trying to accomplish here:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="CLI.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<connectionStrings/>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<applicationSettings>
<CLI.Properties.Settings>
<setting name="URLBase" serializeAs="String">
<value>https://cloud.mycompany.com/</value>
</setting>
<setting name="URLPage" serializeAs="String">
<value>/inventory.aspx#view/Invoice/</value> <!-- This is the value I'm trying to change -->
</setting>
...
I should also mention that I've also tried 'applicationSettings' in place of 'appSettings' in the code above.