C# configSource 在 system.serviceModel * 或 * 其子部分中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/858225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:29:11  来源:igfitidea点击:

configSource doesn't work in system.serviceModel *or* its subsections

c#.netwinformswcfconfiguration

提问by Ryan Lundy

I'm trying to split an app.config file into multiple files to make it easier to manage the differences needed for different environments. With some sections it was easy...

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

<system.diagnostics>
    various stuff
</system.diagnostics>

became

变成了

<system.diagnostics configSource="ConfigFiles\system.diagnostics.dev" />

with the "various stuff" moved to the system.diagnostics.dev file.

将“各种东西”移至 system.diagnostics.dev 文件。

But for the system.serviceModelsection this doesn't seem to work.

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

Now I've read suggestions that it doesn't work for system.serviceModelitself, but it works for the sections underneath it: bindings, client, diagnostics, etc. But the same thing happens to me when I try to use configSource with one of them. When I put in

现在,我读过的建议,它不工作system.serviceModel本身,而是它的工作原理为区段下它:bindingsclientdiagnostics等,但同样的事情发生在我身上时,我尝试使用configSource其中一人。当我放入

<system.serviceModel>
  <bindings configSource="ConfigFiles\whateverFile.dev" />

I get:

我得到:

The 'configSource' attribute is not declared.

未声明“configSource”属性。

Has anyone else seen this? Do you know a solution? (Perhaps I have an out-of-date schema or something?)

有没有其他人看过这个?你知道解决办法吗?(也许我有一个过时的架构或什么?)

采纳答案by Martin Peck

VS.NET's editor moans about the config, but it works.

VS.NET 的编辑器抱怨配置,但它有效。

I have config like this...

我有这样的配置...

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

... which works fine.

......这工作正常。

回答by marc_s

It will NOTwork on <system.serviceModel>since that's a configuration SectionGroup - not a configuration Section.

不会工作,<system.serviceModel>因为那是配置 SectionGroup - 不是配置 Section。

It WILLwork just fine at runtime on anything below <system.serviceModel>- we do this all the time. Martin's answer shows it nicely - his sample will work.

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

回答by Chris

One thing to be aware of when moving your config sections to separate files: make sure your separated config file does NOT contain a configSource attribute. For example, if you split your your bindings section out like so,

将配置部分移动到单独的文件时要注意的一件事:确保单独的配置文件不包含 configSource 属性。例如,如果您像这样拆分绑定部分,

<system.serviceModel>
    <bindings configSource="yourConfigFile.config" />
</system.serviceModel>

make sure that your actual bindings file doesn't contain the "configSource" attribute:

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

<?xml version="1.0" encoding="utf-8"?>
<bindings>
    <!-- binding configuration stuff -->
</bindings>

I know that might seem obvious, but if you enter the configSource attribute, then cut and paste into a new file, it's easy to forget to take the attribute out.

我知道这似乎很明显,但是如果您输入 configSource 属性,然后将其剪切并粘贴到新文件中,很容易忘记删除该属性。

Hope this helps.

希望这可以帮助。