通用配置文件

发布于 2024-12-13 09:29:31 字数 145 浏览 4 评论 0原文

我有 4 个 .net 控制台应用程序,它们执行不同的任务。这 4 个应用程序共享一些我通过 app.config 文件传递​​的通用配置。我可以将所有配置放在一个通用配置文件中并从中读取,而不是分别读取 4 个 applicationname.exe.config 文件吗?

I have got 4 .net console applications which carry out different tasks. These 4 applications share some common configuration that I pass through app.config file. Can I put all the configuration in one common config file and read from that instead of each of the 4 applicationname.exe.config file?

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

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

发布评论

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

评论(2

意犹 2024-12-20 09:29:31

您可以使用 ConfigSource。基本上,它们允许您引用 app.config 中的不同文件。

这是它的工作原理,

<configuration>
  <system.serviceModel>
    <services configSource="External.config" />
  </system.serviceModel>
</configuration>

External.config

<services>
   <!-- Put what you were going to put in the Service element-->
</services>

您需要做的是将所有配置文件中的公共部分“重构”为外部文件,并从主配置文件中引用它们。

You can use ConfigSource. Basically they allow you to reference different files within your app.config.

here is how it would work,

<configuration>
  <system.serviceModel>
    <services configSource="External.config" />
  </system.serviceModel>
</configuration>

External.config

<services>
   <!-- Put what you were going to put in the Service element-->
</services>

what you need to do is to 'refactor' the common parts from all the config files to external files and reference them from your main config files.

思慕 2024-12-20 09:29:31

是的,你可以这样做。如果您创建一个单独的配置项目并从不同的项目中引用它们,您可以访问相同的键/值对。 IE;配置。

看看我之前的问题

Yes you can do that. if you create a separate configuration project and refer to them from your different projects you can access the same key/value pairs. ie; configuration.

Look at my previous question.

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