views:

2197

answers:

3

Update: this question, including the title, was rephrased, see history for details

I know that the following App.config includes a external file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings configSource="appSettings.config"/>
  <system.net>
    <connectionManagement>
      <add address="*" maxconnection="50"/>
    </connectionManagement>
  </system.net>
</configuration>

But I don't know how to move the system.net to the second file. Actually I haven't tried it, but I am almost certain that it will not work, and I want to know if there is an way for an App.config to include another App.config file by reference.

+2  A: 

I think you just remove the configSource attributes and then include all the content within the <appSettings> and <connectionStrings> elements

Adrian
But I still need it to be 2 separate files, the first one referencing the second one who actually contains the configuration.
Jader Dias
Q: "dll share the apps .config" A: Yes I know. Q: "why do you need the system.net section in another file?" A: That was just an example, for my full motivation see the newest comment I wrote to this question.
Jader Dias
+3  A: 

You should not put the system.net section inside the appSettings.config. The standard practice is one config node in a sub config file. I'm not even sure if it's possible to share the same file with different nodes.

You should create another file named perhaps system.net.config and place the entire body in there, the full

  <system.net>
    <connectionManagement>
      <add address="*" maxconnection="50"/>
    </connectionManagement>
  </system.net>

Then in the App.config you will update the system.net to be

  <system.net>
    <connectionManagement configSource="system.net.connectionManagement.config"/>
  </system.net>
Chris Marisic
`system.net` cannot declare a `configSource`.
bzlm
updated answer to put configSource 1 level deeper, kind of pointless to DV an answer that is essentially correct but off from free hand coding...
Chris Marisic
+2  A: 

I was able to get this to work using configSource

<configSections>
    <section name="Sites"
             type="Wap.Common.Configuration.SiteHandler, Wap.Common" />
</configSections>

<Sites configSource="Sites.Prod.config" />

and then in the external config file it needs to have the ?xml tag

<?xml version="1.0" encoding="utf-8" ?>
<Sites>
...
</Sites>

and then you need to set up the external config file to always copy to the output directory

Nick