How do I select a .Net application configuration file from a command line parameter?

前端 未结 5 1453
失恋的感觉
失恋的感觉 2021-01-01 19:20

I would like to override the use of the standard app.config by passing a command line parameter. How do I change the default application configuration file so that when I a

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 19:24

    I needed to do this for an app of mine as well, and dealing with the standard config objects turned into such a freakin' hassle for such a simple concept that I went this route:

    1. Keep multiple config files in XML format similar to app.config
    2. Load the specified config file into a DataSet (via .ReadXML), and use the DataTable with the config info in it as my Configuration object.
    3. So all my code just deals with the Configuration DataTable to retrieve values and not that craptastically obfuscated app config object.

    then I can pass in whatever config filename I need on the command line and if one isn't there - just load app.config into the DataSet.

    Jeezus it was sooo much simpler after that. :-)

    Ron

提交回复
热议问题