移动应用程序时,用户设置会重置 [英] User settings reset when the application is moved

查看:105
本文介绍了移动应用程序时,用户设置会重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,如果将该应用程序.exe文件移动到另一个位置,则用户设置会重置.

I've noticed that if you move that application .exe file in another location the user settings reset.

在我的理解中,发生这种情况是因为app数据文件夹中的位置也基于.exe的路径,在生成哈希值时会将其考虑在内.

In my understanding this happens because the location in the app data folder is based on the path of the .exe as well, which is taken into consideration when the hash is being generated.

我知道有不同的选择,可以通过使用注册表或通过手动创建自定义配置文件来实现,但是我的问题是,当应用程序(.exe)通过以下方式移动到另一个位置时,是否可以保留用户设置? Microsoft提供的默认功能?

I know there are different alternatives, either by using the registry or by creating manually a custom config file, but my question is, is it possible to retain the user settings when the application (.exe) is moved to another location with the default functionality Microsoft provides ?

对于我的测试,我使用一个独立的应用程序(仅一个.exe文件).只需将文件移至(例如,从/Desktop/中的/Desktop/Test/),就会在C:\Users\<user>\AppData\Local\<company>\Appname_Url_<hash>下生成一个新文件夹,其中包含默认的user.config.旧的user.config仍然可用,因此,如果将.exe文件移回其先前的位置,则会再次加载先前的设置.这不仅麻烦,不仅因为您丢失了设置,而且如果将文件在10个不同的位置中移动10次,最终将在appdata中出现10个新文件夹.

For my tests I use a standalone application (one .exe file only). Simply moving the file to, lets say /Desktop/Test/ from /Desktop/ causes a new folder to be generated under C:\Users\<user>\AppData\Local\<company>\Appname_Url_<hash> with the default user.config in it. The old user.config is still available so if you move the .exe file back to its previous location then the previous settings get loaded again. This becomes troublesome not only because you lose the settings, but if you move the file 10 times in 10 different locations you end up with 10 new folders in the appdata.

推荐答案

这实际上是一项安全功能,与程序集部署和clickonce相关. 我认为您只需要在主要部件中添加一个强名称即可解决此问题.

This is in fact a security feature, related to assembly deployment and clickonce stuff. I think you just need to add a strong name to the main assembly to overcome this issue.

如果您没有强名,该名称将类似于此名称,并且如果应用程序路径更改,该名称也会更改(请参见Url令牌):

If you don't have a strong name, the name will be something like this and it will change if the application path change (see the Url token):

%appdata%\WindowsFormsApplication1\WindowsFormsApplication1._Url_3pei3cdnq3srqpjiwh1qnf12ncsp5c2w\1.0.0.0\user.config

如果您有一个强名,它将是这样,并且不会更改,因为现在可以识别您的应用来源,无论其当前位置在哪里(请参见StrongName令牌):

If you have a strong name it will be something like this and it will not change because your app origin is now identified, whatever its current location is (see the StrongName token):

%appdata%\WindowsFormsApplication1\WindowsFormsApplication1._StrongName_fe0ndyau2vlgeac4gmbg13u3q4jtyrqv\1.0.0.0\user.config

这篇关于移动应用程序时,用户设置会重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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