Updating .config file from an Custom Installer Class Action

后端 未结 5 1276
春和景丽
春和景丽 2021-02-04 20:03

I\'ve tried updating my application\'s .config file during installer (via a .NET Installer Class Action). But, I can\'t seem to get ConfigurationManager to lis

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 20:26

    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. :)

提交回复
热议问题