configSource在system.serviceModel*或*子节中不起作用

Rya*_*ndy 33 .net c# configuration wcf winforms

我正在尝试将app.config文件拆分为多个文件,以便更轻松地管理不同环境所需的差异.有些部分很容易......

<system.diagnostics>
    various stuff
</system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

成为

<system.diagnostics configSource="ConfigFiles\system.diagnostics.dev" />
Run Code Online (Sandbox Code Playgroud)

将"各种东西"移动到system.diagnostics.dev文件中.

但对于这system.serviceModel部分,这似乎不起作用.

现在,我读过,它不工作的建议system.serviceModel本身,但它工作的部分它的下面:bindings,client,diagnostics等,但同样的事情发生在我身上时,我尝试使用configSource其中一人.当我投入

<system.serviceModel>
  <bindings configSource="ConfigFiles\whateverFile.dev" />
Run Code Online (Sandbox Code Playgroud)

我明白了:

未声明'configSource'属性.

有没有人见过这个?你知道解决方案吗?(也许我有一个过时的架构或什么?)

Mar*_*eck 66

VS.NET的编辑器对配置感到不满,但它确实有效.

我有这样的配置......

<system.serviceModel>
  <behaviors configSource="config\system.servicemodel.behaviors.config" />
  <bindings configSource="config\system.servicemodel.bindings.config" />
  <client configSource="config\system.servicemodel.client.config" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

......工作正常.

  • 晚到派对并意识到这一点,但我不得不为每个配置文件设置'复制到输出目录'到'始终复制'以获得可接受的解决方案.希望能帮助到你. (3认同)

mar*_*c_s 24

不会起作用,<system.serviceModel>因为这是一个配置SectionGroup - 而不是配置部分.

WILL在运行时工作得很好,下面什么<system.serviceModel>-我们做这一切的时候.马丁的答案很好地表明了 - 他的样本将起作用.


小智 6

将配置节移动到单独的文件时需要注意的一点是:确保分离的配置文件不包含configSource属性.例如,如果您将绑定部分拆分出来,

<system.serviceModel>
    <bindings configSource="yourConfigFile.config" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

确保您的实际绑定文件不包含"configSource"属性:

<?xml version="1.0" encoding="utf-8"?>
<bindings>
    <!-- binding configuration stuff -->
</bindings>
Run Code Online (Sandbox Code Playgroud)

我知道这似乎很明显,但是如果你输入configSource属性,然后剪切并粘贴到一个新文件中,很容易忘记将该属性输出.

希望这可以帮助.