是否可以组合app.config文件和web.config文件.我是自托管服务并在IIS中托管它,发现自己必须编辑两个不同的文件?
是的,你可以"外化"的相关配置节到单独的文件,并引用那些来自app.config和你的web.config.
任何.NET配置部分都可以存储到外部配置文件中,因此您可以编写:
<system.serviceModel>
<bindings configSource="bindings.config" />
<behaviors configSource="behaviors.config" />
<client configSource="client.config" />
....
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
现在,您的外部文件看起来与配置中的相关配置部分完全相同:
bindings.config
<?xml version="1.0" encoding="utf-8" />
<bindings>
<basicHttpBinding>
<binding name="......." ...... />
</basicHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
注:Visual Studio的编辑器会抱怨configSource=属性-但智能感知混合起来-的configSource属性是存在于每个配置部分,以及它的工作就好了!
注意#2:您不能将整个外部化,<system.serviceModel>因为这是一个配置节组 - 不幸的是,那些没有任何方法可以放入外部文件.