如何通过的app.config变量来覆盖settings.settings变量 [英] How to override settings.settings variable by app.config variable

查看:208
本文介绍了如何通过的app.config变量来覆盖settings.settings变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过在生产时向app.config添加一个变量来更改(或覆盖)一个settings.settings变量?

How can I change (or override) a settings.settings variable by adding a variable to the app.config on production?

p>

推荐答案

您必须直接引用您尝试覆盖的applicationSettings,并显式指定具有替换值的属性。

You have to directly reference the applicationSettings you're trying to override and explicitly specify the property that has a replaced value.

<configuration>
  <!-- section definitions for all elements in <configuration> tag -->
  <configSections>
    <!-- section group, meaning: there will be a <applicationSettings> tag in you configuration-->
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <!-- defines that there will be a <appname.Properties.Settings> tag inside your <applicationSettings> tag -->
      <section name="appname.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <applicationSettings>
    <appname.Properties.Settings>
      <!-- name of the property you want to override -->
      <setting name="setting1" serializeAs="String">
        <!-- new value -->
        <value>new string value</value>
      </setting>
    </appname.Properties.Settings>
  </applicationSettings>
</configuration>

这篇关于如何通过的app.config变量来覆盖settings.settings变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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