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

查看:35
本文介绍了如何通过 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?

这可能吗?

推荐答案

您必须直接引用您要覆盖的 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天全站免登陆