Use app.config correctly

In several C # projects, I use the app.config file to pass various parameters to my program, such as connection settings, power levels, etc.

However, sometimes I came in a situation where the settings did not update as expected, and I came to the conclusion that I was not so well informed about the proper use of the app.config file.

Example:

  • Replacing the .exe file with the new version (where the settings are different) in the output directory without changing exe.config, as a result, the program will see the hard-set settings, and not the settings of the existing .exe.config

So my questions are:

  • What is the exact role of the exe.manifest file
  • Every time I create a new .exe, do I need to insert anything else besides the .exe file in the output folder?
  • What is the difference in getting the parameter value: ConfigurationManager.'settingName'...instead of Properties.Settings.Default.'settingName':?
  • What is the role of app.config build action?

Sorry if I ask too many questions in one question.

+4
source share
3 answers

The app.config file is a file that receives special processing when the corresponding application is launched. If the executable file has a name MyApp.exe, the app.config file must have a name MyApp.exe.config. The role of the app.config build task is to copy the file with the name app.configto the project in MyApp.exe.configto the output directory.

.NET ( XML), .NET XML .

- , Properties.Settings.Default. Visual Studio, . . , app.config.

Visual Studio , . , app.config, . app.config .

app.config , oppinion Visual Studio .

, , . MyApp.exe MyApp.exe.config , , (, , ).

. app.config.

+4

Maybe one thing you could do if you want to copy only the .exe file each time you create your application, create a settings.ini or settings.txt file, put your parameters in this file (this is not a secret course ) and read all your settings from there when you start the application. You can put all the connection string logic in your login form if you have ...

-1
source

Source: https://habr.com/ru/post/1537681/


All Articles