如何通过代码将自定义 configSections 添加到 app.config 文件

how to add custom configSections to app.config file through code

如何通过代码向 app.config 文件添加部分?

我的配置文件中有类似的内容,但它可以有多个部分但不能通过 appSettings,因为我想向它添加多个值。

<configSections>
 <!-- CUSTOM CONFIG SECTIONS BELOW -->
 <section name="EmailSection" type="Email.EmailSection, Email" />
</configSections>

<EmailSection>
 <Emails>
  <email id="HOST" name="mail.somedomain.com" />
  <email id="PORT" name="25" />
  <email id="TOADDRESS" name="" />
  <email id="FROMADDRESS" name="dev@somedomain.com" />
 </Emails>
</EmailSection>

我想通过我的代码中的导入方法来做到这一点,这样我就可以 select 一个 xml 文件,然后将这些部分添加到我的 app.config.

此致

艾丹

设法通过 this 完成这项工作。

我不得不遍历我的项目并将它们添加进去,但它做了我需要的。

谢谢你的建议。

艾丹