Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override settings.settings variable by app.config variable

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

Is this possible anyway?

like image 470
Schrander Avatar asked Jul 07 '11 09:07

Schrander


People also ask

How read app config file in C# Windows application?

New Project > Visual C# > Console ApplicationConfiguration assembly reference to access configuration settings, using ConfigurationManager. To add the reference, just right click References and click to add references. Now, we can see that System. Configuration reference has been added successfully to our project.

When should I use app config?

App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.


1 Answers

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>
like image 125
Arjun Shetty Avatar answered Oct 29 '22 15:10

Arjun Shetty