I have a .NET application. Its source code performs no config file manipulations. I am wondering whether there is a way to instruct the CLR to bind the app to another config file. A command line switch is perfect, but as far as I know no such thing exists.
A registry change could be a solution, as long as it is consulted only during the application start, because I wish to run two instances of the app with 开发者_Python百科different config files. So, if the registry is consulted during the app lifetime - no good.
Anyway, there could be other options. Still, I am unaware of any.
Anyone?
Thanks.
Make a loader exe which does 2 following things:
Reloads custom
app.config
file as shown here: Change default app.config at runtimeUses
Assembly.Load()
+ invokes theassembly.EntryPoint
Or, even better, create a new
AppDomain
, usedomain.SetData("APP_CONFIG_PATH", your_path)
+domain.ExecuteAssembly(your_file_name)
.
Other gotchas you're may run into:
- COM Apartment of the new thread
- Message loops already running
- WPF dispatchers already created
- possibly more :) Please post any exceptions/misbehaviours. I just don't have the code at hand right now to test, but did it before a couple of times.
精彩评论