How to override settings.settings variable app.config variable

How can I change (or override) the settings.settings variable by adding the variable to app.config when I create it?

Is this possible anyway?

+5
source share
5 answers

You need to directly refer to the application settings that you are trying to override, and explicitly specify the property with the 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>
+7
source

Application Area Connection String Value:

  <connectionStrings>
    <add name="appname.Properties.Settings.setting1" connectionString="test string" providerName="dbProvider"/>
  </connectionStrings>
+1
source

. , app.config, .

, , , app.config, , , , , . config, app.config , .

- . :

0

. RELEASE, , Visual Studio , -, RELEASE, .

, , - , , if/else.

0

:

.

 if (bool.Parse(ConfigurationManager.AppSettings["overridethis"].ToString()))
 {
     //use overridden value
 }

, , , AppSettings.

.

 <appSettings file="..\user.config">

See http://www.compiledthoughts.com/2005/03/overriding-webconfig-app-settings-with.html

-1
source

All Articles