是否可以将 .NET 应用程序配置为使用不同的配置文件,而无需专门采用源代码来支持这种需求?

发布于 2024-10-09 01:32:07 字数 251 浏览 0 评论 0原文

我有一个 .NET 应用程序。它的源代码不执行任何配置文件操作。我想知道是否有办法指示 CLR 将应用程序绑定到另一个配置文件。命令行开关是完美的,但据我所知不存在这样的东西。

注册表更改可能是一个解决方案,只要仅在应用程序启动期间查阅它即可,因为我希望使用不同的配置文件运行应用程序的两个实例。因此,如果在应用程序生命周期内查阅注册表 - 没有好处。

无论如何,可能还有其他选择。尽管如此,我还是不知道。

有人吗?

谢谢。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不如归去 2024-10-16 01:32:07

制作一个可执行以下 2 件事的加载程序 exe:

  1. 重新加载自定义 app.config 文件,如下所示:在运行时更改默认 app.config

  2. 使用 Assembly。 Load() + 调用 Assembly.EntryPoint

  3. 或者,更好的是,创建一个新的 AppDomain,使用 domain.SetData("APP_CONFIG_PATH", your_path) + domain.ExecuteAssembly(your_file_name)或者

您可能会遇到的其他问题:

  • 新线程的 COM 单元
  • 消息循环已在运行
  • WPF 调度程序,可能已创建
  • 更多:) 请发布任何异常/不当行为。我只是现在手头没有代码来测试,但之前做过几次。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文