Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple App.Config files

Tags:

c#

app-config

I want to separate my app.config file. For example I want to move ServiceModel part to another config file in the same project. How can I do that?

Thanks.

like image 774
hovkar Avatar asked Apr 01 '10 11:04

hovkar


People also ask

Can we have multiple config files?

Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration.

Can we have multiple app config files in C#?

Multiple config files can be used, and it is a useful solution to a scenario where you want to deploy config changes that are isolated to one functionality of your app.

Can I use more than one Web config file in Solution?

You can have 1 Web. config file per folder . So in your root you can have a web. config and in a subfolder you can have another one that overrides settings from the one in the root.


2 Answers

You should be able to have an empty element with the configSource attribute set to the second file (relative to the first). See here for how to enable it for custom sections.

like image 73
Marc Gravell Avatar answered Sep 23 '22 14:09

Marc Gravell


I found the way. I changed the tag like this.

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

After I created the Services.config file and their I put this

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

The same I done in Bindings, Behaviors, Extensions.config files.

And it works

like image 25
hovkar Avatar answered Sep 21 '22 14:09

hovkar