In a .NET Win console application, I would like to access an App.config file in a location different from the console application binary. For example, how can C:\\bin\\Text.
It appears that you can use the AppDomain.SetData method to achieve this. The documentation states:
You cannot insert or modify system entries with this method.
Regardless, doing so does appear to work. The documentation for the AppDomain.GetData method lists the system entries available, of interest is the "APP_CONFIG_FILE"
entry.
If we set the "APP_CONFIG_FILE"
before any application settings are used, we can modify where the app.config
is loaded from. For example:
public class Program
{
public static void Main()
{
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\Temp\test.config");
//...
}
}
I found this solution documented in this blog and a more complete answer (to a related question) can be found here.