Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

splitting appsettings section of app.config in two parts

Tags:

c#

.net

vb.net

I have a windows application and its being deployed via click once. My appsettings inside my app.config have several settings. Some settings are deployment specific like the webserver source for the file download etc. It will vary with deployment region. Some settings items are app specific which wont change during deployment.

<appSettings >    
   <add key="key1" value="Value111 changable with region" />
   <add key="Key2" value="Value222 changable with region" />

    <add key="key3" value="Value333 NOT changable with region" />
   <add key="Key4" value="Value444 NOT changable with region" />

 </appSettings > 

Now I need to split my appsettings in two app.config files. I want to put key1 and key2 in separate config files. How do I do that.

like image 663
Abbi Avatar asked Jun 20 '14 21:06

Abbi


1 Answers

Use the appSettings file attribute and give each deployment region its file version.

app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings file="regionsettings.config">
      <add key="key1" value="default value" />
      <add key="commonKey" value="common value" />
  </appSettings>
</configuration>

regionsettings.config (region 1):

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
    <add key="key1" value="region 1" />
</appSettings>

regionsettings.config (region 2):

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
    <add key="key1" value="region 2" />
</appSettings>

Or do like Henk suggested:

<add key="region1.key1" value="region1key1 value" />
<add key="region2.key1" value="region2key1 value" />
like image 85
Jasen Avatar answered Oct 23 '22 23:10

Jasen