开发者

Is it possible to configure a .NET application to use a different config file without specifically adopting the source code to support such a need?

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:

  1. Reloads custom app.config file as shown here: Change default app.config at runtime

  2. Uses Assembly.Load() + invokes the assembly.EntryPoint

  3. Or, even better, create a new AppDomain, use domain.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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜