I have created a simple windows application and added a App.config file
I have also added Settings file which also adds keys into App.config file.
<appSettings>
<add key="myKey" value="1"/>
</appSettings>
<applicationSettings>
<MyApp.AppSettings>
<setting name="RunAutomated" serializeAs="String">
<value>False</value>
</setting>
</MyApp.AppSettings>
</applicationSettings>
Inside my code have the following :
If(AppSettings.Default.RunAutomated) {
Console.WriteLine("Running auto!!!");
}
else {
Console.WriteLine("Running manual!!!");
}
Simple is that.
When I build the project and run it through visual studio everything is as expected that output changes when I change RunAutomated key and re run the application.
But this is not true when I go under /bin/Debug folder and run the MyApp.exe
It seems to cache app.config and it ignores the changes to app.config file.
How should I do this simple task to keep reading the App.config file every time it is run? any changes I am making app.config should affect the application?
app.configis copied toAppName.exe.configevery build. So when rebuilding, you're back to defaults.app.configwhere absolutely necessary (e.g. assembly redirection). For custom configuration I'd use a separate file together with some serializer.