title: How to merge the applicationSettings of a class library into the host executable's config file
body: <p>I am reading articles, forum posts about applicationSettings for almost a week now.</p>
  
  <p>In almost every thread there was someone that appears to have correctly pointed out that the class libraries cannot have config files when deployed and their applicationSettings configured at design must be specified/merged in the <em>executable</em>.exe.config configuration file of the application that host/consumes the dll. </p>
  
  <p>Not necessarily true. </p>
  
  <p>You can but you don't need to merge them class library settings unless you want to provide the user with a way to "overwrite" the default values - the ones that are specified using the DefaultValueAttribute hard coded in the assembly. </p>
  
  <p>So, for a very simple, practical example. Let's use VB.NET
  1. I created a Class Library project called ClassLibrary. 
  2. Showing all files, expand MyProject, double click Settings.settings.
  3. Adding a setting called Message, application scoped whose value is "Hello!".
  4. Create a property in Class1.vb (the automatically added class)</p>
  
  <pre><code>Public Class Class1
  
      Public Shared ReadOnly Property Message As String
          Get
              Return My.Settings.Message
          End Get
      End Property
  
  End Class
  </code></pre>
  
  <ol>
  <li>Create a VB WinForms project and call it WinForm.</li>
  <li>Add a reference to the ClassLibrary project.</li>
  <li><p>Add a button to the already created Form1 and double click on it.
  8 Add the some code to the the Button1_Click handler. Should look like this.</p>
  
  <p>Public Class Form1</p>
  
  <pre><code>Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
      MessageBox.Show(ClassLibrary.Class1.Message)
  End Sub
  </code></pre>
  
  <p>End Class</p></li>
  <li><p>Have WinForm "Set as Startup project"</p></li>
  </ol>
  
  <p>Now, while in the IDE everything works beautifully. Run the solution and you'll get the expected Hello! when you press the button. If you go and change the setting in the app.config of the library to say "Good bye!" and you run the solution again you get a "Good bye!"</p>
  
  <p>However, right click on the WinForm project and "Open in Explorer" and get to the Debug folder. There's no WinForm.exe.config file yet. Let's create one quickly.
  Switch back to VS and while the WinForm project is selected click to Show All Files.
  Expand MyProject, open Settings.settings, create a setting (doens't matter what) and save.
  There we go, an App.config was created and if I build this solution, the Debug folder will contain a WinForm.exe.config.</p>
  
  <p>Tell me how I merge my Message setting from the class library config</p>
  
  <pre><code>&lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="ClassLibrary.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
  
      &lt;applicationSettings&gt;
          &lt;ClassLibrary.My.MySettings&gt;
              &lt;setting name="Message" serializeAs="String"&gt;
                  &lt;value&gt;Hello!&lt;/value&gt;
              &lt;/setting&gt;
          &lt;/ClassLibrary.My.MySettings&gt;
      &lt;/applicationSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>into the WinForm's config </p>
  
  <pre><code>&lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="WinForm.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;startup&gt;
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" /&gt;
      &lt;/startup&gt;
      &lt;applicationSettings&gt;
          &lt;WinForm.My.MySettings&gt;
              &lt;!--&lt;setting name="A" serializeAs="String"&gt;
                  &lt;value&gt;A&lt;/value&gt;
              &lt;/setting&gt;--&gt;
          &lt;/WinForm.My.MySettings&gt;
      &lt;/applicationSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>so I can change the Message setting's value in the WinForm.exe.config to something else and the application will display this new value overriding the DefaultValueAttribute.</p>