Location of app.config file used by referenced library for My.Settings?

后端 未结 2 1347
情话喂你
情话喂你 2021-01-22 02:36

If I have a class library with an app.config file (I know it\'s not ideal, just bear with me for a moment) which has settings values created by using the projects S

相关标签:
2条回答
  • 2021-01-22 03:01

    Edited after reading comments.

    I think I see what your after. The My.Settings will used the compiled values from your class libs settings as default values. I believe these are compiled in. You can reflect the source though to see if it is setting a defaultvalue attribute on them.

    You can override these by setting the values in the main exe's application file. If the settings aren't in the exes file, then you will use the default ones you specified in your class libs.

    You shouldn't care about the file name. Just assume the settings are either defaulted or were overridden. If you need to know if they were overridden, that's another issue.

    0 讨论(0)
  • 2021-01-22 03:05

    but that returns the application's config file. How can I determine which .config file the library is reading from when it calls My.Settings...?

    • By default, it will be always the main.exe.config.

      Take a look at this for detailed answer C# DLL config file for more informations

    • You can use external config files. This article on MSDN explains how.

    EDIT

    You're misunderstanding the situation, reread this line: The settings from the app.config file of the library project are definitely not copied into the app.config file of the application but I can sti retrieve the My.Settings from the libraries app.config.

    You are correct. Your settings in the dll.config will not be copied automatically in the app.config.

    Concerning the value that you are able to get from your dll, I am still looking for more official answer, but the answer seems to be:

    the 'old' values (the ones you define at development time) are hard coded. If the franework isn't able to access or open the config file it will use the defaults instead. This will always happen if you use settings in a dll.

    Take a look at this Settings.Default.<property> always returns default value instead of value in persistant storage (XML file)

    0 讨论(0)
提交回复
热议问题