How do I compile my App.config into my exe in a VS2010 C# console app?

前端 未结 10 1965
傲寒
傲寒 2020-12-05 17:24

I\'m creating a console app in Visual Studio 2010 with c#. I want this app to be stand alone, in that all you need is the exe, and you can run it from anywhere. I also want

10条回答
  •  生来不讨喜
    2020-12-05 17:59

    Generally, you don't want to do this as your app.config provides a mechanism by which configuration may be done at runtime. As far as you specific goal (maintaining configuration outside of your code, but have it follow the binary), you have a couple of options:

    • Dynamically create a configuration file
    • Store the settings in the registry
    • Store the settings as resource strings within the console application

    I am sure there are other, more creative, options available. My recommendation would be for the second option. When the application is first launched, create the necessary keys and set their default values from the executable. That way, if you need to do any debugging at a later date, you can simply run regedit and make any necessary changes without recompiling.

提交回复
热议问题