Application settings appear after clean when program copied elsewhere

折月煮酒 提交于 2019-12-07 23:20:53

问题


I have a WinForm project with one form and an application settings file. When the form loads, it reads from application settings and if the program successfully runs (i.e. the file is written to the destination) the application settings are saved for the next runs.

I am noticing a strange behavior as I build my solution:

When I clean and rebuild my solution and test my program in the bin/Release folder, everything looks fine and the application settings are clear. But when I copy the same files to another destination and run the program from there (even though the .exe.config file is also replaced with the new clean version) it seems that the copy version still remembers my application settings. What could possibly cause this?


回答1:


When you use Settings.Settings in a normal way, considering these facts will help you to have a better understanding about user settings:

  • When you save settings using Properties.Default.Settings.Save() current values for user settings are stored in %userprofile%\appdata\local in a folder with the name of your application in a sub folder which is unique for deployment.

  • Each deployment has a unique path, so when you copy your application in a previously used path, it assumed as an update to your previous deployment and your previous user setting will be remembered and merged with new added settings.

  • If you copy the application in a totally new path, it assumed as a new deployment and your previous user settings will not be remembered.

  • Only the default values are stored in .config file beside .exe of your application, so deleting them has no impact on remembering the user saved values.



来源:https://stackoverflow.com/questions/35864376/application-settings-appear-after-clean-when-program-copied-elsewhere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!