A: 

Instead of accessing your settings configuration via ConfigurationManager, you should be able to access it via Settings.Default. Settings are more of a Visual Studio feature than a .NET feature...a convenience that makes it easy to visually design your applications configuration rather than manually writing it in appSettings or creating custom configuration sections. However, the configuration schema that is rendered when you use Settings is non-standard, and can be difficult to access manually.

Visual Studio should have generated a Settings class for you when you built your application, and you should be able to access that class via Properties.Settings.Default. It should have a property for each setting, in your case, the following:

Properties.Settings.Default.TESTSETTING
Properties.Settings.Default.VerboseErrorMode
Properties.Settings.Default.RunOnStartup

You should be able to both read and write these settings. A critical thing to note...anything flagged as a "user" setting will not be written back to the {yourapplication}.exe.config file...it will be written to a User.config file in the users isolated profile storage area. This is under C:\Documents and Settings{username} on XP, and C:\Users{username} on Vista, in the AppData folder. Depending on the OS and users profile, the subfolder under the AppData may change, but its completely unique and keyed to a particular version of the application. Installation of a newer version will result in a completely new set of configuration settings stored under the same keyed folder, but a different version subfolder.

I hope this helps. :)

jrista
@jirsta - Thanks for your detailed post. The reason I am using the ConfigurationManager is I am trying to update the settings from an Installer via a custom Installer Class Action. These settings need to become the default settings for ALL USERS and hence the reason why I am using ConfigurationManager since it will apparently write the changes to the <appName>.config file from which all individual user.configs are inherited from.
blak3r
In that case, it might actually be easiest to just load up an XmlDocument and edit the data directly. The settings schema is pretty simple overall.
jrista
A: 

One thing to try is moving it from install to Commit to ensure that the file has been written first before trying to access it. Alternatively you could use the custom action to write your own file and just alter your config file to point at the alternative xml file.

I worked on a Sharepoint product install where I dug into all of this and I will admit it is very tedious to get working correctly. I was creating config and batch files on the fly based on install parameters.

Peter
Hi Peter, I am performing this task during the Commit step and I have verified that the file does exist. I'm getting close to just writing a XML file editor and not trying to do it with .NET altogether...
blak3r
hmm that is strange. I don't think the issue is with .Net itself, customizing the basic installers in visual studio isn't as advanced as it should be. We use a tool called FinalBuilder at my work whenever we do full release versions.If you do go the route of creating a custom xml file, you may want to look into 2 technologies either of which would help. Linq to XML will allow you to create xml structures, or Xml Serialization which allows you to decorate your classes with their XML document element syntax, you then use an xml serializer to turn them into xml.hope this helps
Peter
A: 

This is what you need: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f89a00eb-9400-48ce-af20-cef78002c14e

Khalil Dahab
Thanks - It'd be great if there was actually an answer to that user's post... he appears to be having a similar problem but no answer. Nonetheless, the post does use some different methods for accessing the config file which i've never seen before... so maybe i'll give it a try.
blak3r
+2  A: 

I came across the same problem, after deep investigation, I found out the easiest way to update any part of config files (e.g. app.config), that's by using XPath. We have an application which connects to web service, during the installation, the user enters the URL of the web service and this should be saved in the following app.config file:

     <?xml version="1.0"?>
 <configuration>
   <configSections>
  <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <section name="ApplicationServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </sectionGroup>
   </configSections>

   <applicationSettings>
  <ApplicationServer.Properties.Settings>
    <setting name="ApplicationServer_ApplicationServerUrl" serializeAs="String">
   <value>whatever comes from setup should go here</value>
    </setting>
  </ApplicationServer.Properties.Settings>
   </applicationSettings>
 </configuration>

Here is the code to do this in the installer class:

public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);

        string targetDirectory = Context.Parameters["targetdir"];
        string param1 = Context.Parameters["param1"];

        string path = System.IO.Path.Combine(targetDirectory, "app.config");

  System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();

        xDoc.Load(path);

        System.Xml.XmlNode node = xDoc.SelectSingleNode("/configuration/applicationSettings/Intellisense.ApplicationServer.Properties.Settings/setting[@name='ApplicationServer_ApplicationServerUrl']/value");
        node.InnerText = (param1.EndsWith("/") ? param1 : param1 + "/");

        xDoc.Save(path); // saves the web.config file  
    }

Basically, since the config file is a XML based document, I am using XPath expression to locate specific node and change its value.

Khalil Dahab
@Khalil Dahab Interesting... Thanks for the suggestion. I'll give it a try soon and report back.
blak3r
@Khalil Dahab -- I just tried it out. Works great. Thanks again.
blak3r
A: 

Hello, I need help with this too. I have an Installer class, that runs some code to update a config file. The code works perfectly on it's own. I place this into the installers 'Protected Overrides Sub OnBeforeInstall' sub. I knwo it runs, as it opens a file dialogue asking for the config file. However, once I feed it the file and the file dialogue closes, the installation seems to hang. It's as if the installer can't tell the file dialogue is closed. Can anyone help? Thanks

Andrew