It looks like you can use the AppDomain.SetData method to achieve this. The documentation states:
You cannot insert or modify system records using this method.
Regardless, this seems to work. The documentation for the AppDomain.GetData method lists the available system records of interest as the "APP_CONFIG_FILE" record.
If we set "APP_CONFIG_FILE" before any application parameters are used, we can change where app.config loaded from. For instance:
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 the corresponding question) can be found.
source share