将app.config的appsettings部分分为两部分 [英] splitting appsettings section of app.config in two parts

查看:53
本文介绍了将app.config的appsettings部分分为两部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序,只需单击一下即可部署它.我在app.config中的appsettings有几个设置.某些设置是特定于部署的,例如文件下载的Web服务器源等.它随部署区域的不同而不同.某些设置项是特定于应用程序的,部署期间不会更改.

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 > 

现在,我需要将我的appsettings分为两个app.config文件.我想将key1和key2放在单独的配置文件中.我该怎么做.

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.

推荐答案

使用appSettings

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 (区域1 ):

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

regionsettings.config (区域2 ):

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

或者像Henk建议的那样做:

Or do like Henk suggested:

<add key="region1.key1" value="region1key1 value" />
<add key="region2.key1" value="region2key1 value" />

这篇关于将app.config的appsettings部分分为两部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆