将应用程序设置存储在项目文件夹而不是 AppData 中
我的项目中有一个 Settings.cs 文件,我通过程序从程序中访问其中的数据
Properties.Settings.Default.MyProperty
生成的设置文件存储在以下位置
C:\Users\Foo\AppData\Local\MyApp\MyApp.exe_Url_jknwq2raeohczydfp1loj02nf05zldfk\1.0.0.0\user.config
问题是,这不仅是用户特定的,而且还会导致程序每个签名(调试/发布等)都有许多 user.config 文件,这迫使开发人员用户每次启动没有特定 user.config 的程序“版本”时再次填充整个设置然而。 (如果我不够清楚,我很乐意提供更多详细信息)
我希望我的应用程序为所有用户提供单个设置文件,无论“版本”如何(调试/发布或其他)。这样,开发用户必须一次性设置这些设置,并且这些设置将在每次启动应用程序时生效,而无需为其他签名/用户重新输入它们。
I have a Settings.cs file in my project, and I access the data in it from my program via
Properties.Settings.Default.MyProperty
The generated settings file is stored in the following location
C:\Users\Foo\AppData\Local\MyApp\MyApp.exe_Url_jknwq2raeohczydfp1loj02nf05zldfk\1.0.0.0\user.config
The problem is that this is not only user specific, but it also results in the program having many user.config files for every signature (debug/release, etc.), which forces the developer-user to populate the whole settings again each time he launches a "version" of the program that does not have a specific user.config yet. (If I am not being clear enough, I'll be glad to give more details)
I would like my application to have a single settings files for all users and no matter the "version" (debug/release, or else). This way, the dev-user would have to set the settings one single time and these settings would be effective each time the application is launched, without the need to re-enter them for the other signatures/users.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像注册表中的所有高级程序一样保存和读取设置,具体方法如下:
另一个选择是创建一个可序列化的类([ Serialized()] attrib),其中包含所有设置作为属性,然后使用 BinaryFormatter 类将其保存在您的应用程序目录中。
You can save and read setting like all advanced programs in Registry, and that is how to do it:
Another choice you have that you make a serializable class ([Serializable()] attrib) that contains all of your settings as properties, then save it in your app directory, with the BinaryFormatter class.
我设计了一个简单的解决方案,但有一些缺点:
问题:您需要 UAC assense 来重写可执行配置,并且不能使用 Properties.Settings.Default.MyProperty 语法。
I have devised a simple solution with some drawbacks:
Problem: You need UAC assense to write over your executable config and you can't use Properties.Settings.Default.MyProperty syntax.
我最终选择了一种更简单直接的替代方案,包括创建一个普通的 Settings 类并按照此处所述对其进行序列化/反序列化
I Finally opted for a simpler straightforward alternative, consisting in creating a plain Settings class and Serializing/Deserializing it as described here