当程序复制到其他位置时,应用程序设置在清除后显示 [英] Application settings appear after clean when program copied elsewhere

查看:105
本文介绍了当程序复制到其他位置时,应用程序设置在清除后显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForm项目,具有一个表单和一个应用程序设置文件.加载表单后,它将从应用程序设置中读取信息,并且如果程序成功运行(即文件已写入目标位置),则会保存应用程序设置以供下次运行.

在构建解决方案时,我注意到一种奇怪的行为:

当我清理并重建解决方案并在bin/Release文件夹中测试程序时,一切看起来都很好,应用程序设置也很清晰.但是,当我将相同文件复制到另一个目标并从那里运行程序时(即使.exe.config文件也已替换为新的干净版本),复制版本似乎仍会记住我的应用程序设置.可能是什么原因造成的?

解决方案

以常规方式使用Settings.Settings时,考虑这些事实将有助于您更好地了解用户设置:

  • 使用Properties.Default.Settings.Save()保存设置时,用户设置的当前值存储在%userprofile%\appdata\local的文件夹中,该文件夹的应用程序名称位于子文件夹中,该文件夹对于部署是唯一的.

  • 每个部署都有一个唯一的路径,因此,当您在以前使用的路径中复制应用程序时,它被认为是对先前部署的更新,并且先前的用户设置将被记住并与新添加的设置合并./p>

  • 如果您以全新路径复制该应用程序,则该应用程序将被视为新部署,并且以前的用户设置将不会被记住.

  • 仅默认值存储在应用程序.exe旁边的.config文件中,因此删除它们不会影响记住用户保存的值.

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?

解决方案

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.

这篇关于当程序复制到其他位置时,应用程序设置在清除后显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆