【问题标题】:Multiple App.Config files多个 App.Config 文件
【发布时间】:2011-02-03 08:08:30
【问题描述】:

我想分离我的 app.config 文件。例如,我想将 ServiceModel 部分移动到同一项目中的另一个配置文件中。我该怎么做?

谢谢。

【问题讨论】:

    标签: c# app-config


    【解决方案1】:

    您应该能够将configSource 属性设置为第二个文件(相对于第一个文件)的空元素。请参阅此处了解如何启用它for custom sections

    【讨论】:

      【解决方案2】:

      我找到了路。我像这样更改了标签。

      <system.serviceModel>
          <behaviors configSource="Behaviors.config">
          </behaviors>
          <services configSource="Services.config">
          </services>
          <bindings configSource="Bindings.config">
          </bindings>
          <extensions configSource="Extensions.config">
          </extensions>
        </system.serviceModel>
      

      在我创建了 Services.config 文件之后,我把它放了

      <services>
        <service behaviorConfiguration="ServiceBehavior" name="EntLib31ExceptionTest.Service1">
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:8001/ValidationService1/" />
            </baseAddresses>
          </host>
          <endpoint address="" 
                     binding="wsHttpBinding" 
                     bindingConfiguration="CustomBinding" 
                     contract="EntLib31ExceptionTest.IService"    
                     behaviorConfiguration="Validation"/>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
      </services>
      

      我在 Bindings、Behaviors、Extensions.config 文件中所做的相同。

      它有效

      【讨论】:

      • @Wilson:您需要学习突出显示您的代码或 XML 行,然后按编辑器工具栏上的“代码”按钮 (101 010) 以很好地格式化它们 - 不需要凌乱的“
      【解决方案3】:

      使用这样的东西:

      <?xml version="1.0"?>    
      <configuration>    
          <appSettings />    
          <connectionStrings/>    
          <system.web>    
              <compilation debug="false" strict="false" explicit="true" />    
          </system.web>    
          <appSettings file="externalSettings.config"/>    
      </configuration>
      

      【讨论】:

        【解决方案4】:

        据我所知,这很遗憾是不可能的。

        您可以做的是(如果我们谈论的是 WCF 代理)在您的代码中创建和配置您的代理。这样你就不需要 serviceModel 部分了。

        现在只需为您需要的数据定义您自己的自定义部分,然后可以将其放在您的配置文件之外。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-11-23
          • 1970-01-01
          • 1970-01-01
          • 2010-09-07
          • 2013-04-09
          • 2011-05-26
          • 1970-01-01
          • 2011-02-04
          相关资源
          最近更新 更多