本文介绍了如何使用Properties.CustomSettings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据MSDN ,可以将自定义的设置文件添加到一个项目中,以方便管理设置组.

According to MSDN, one can add customized settings files to ones project for convenient management of groups of settings.

因此,我通过可视化设计器创建了一个自定义设置,将所有属性设置为用户范围"以能够保存它们.我将一些控件属性绑定到该自定义设置.并通过Properties.CustomSettings.MyValue = x;

So I created a custom settings by visual designer, set all properties as a User Scoped to be able to save them.I bind some control properties to this customized settings. And change some values mannually through Properties.CustomSettings.MyValue = x;

但是当我执行Properties.CustomSettings.Default.Save()时-什么也没发生.更改不会在应用程序运行之间持久保存(我知道Debug版本的更改).

But when I do Properties.CustomSettings.Default.Save() - nothing happens. The changes are not persisted between application run (I'm aware about Debug version change) .

我在目录中搜索了ConfigurationManager给我的文件 (根据这篇文章),但未找到此CustomSettings的任何踪迹.

I searched a file in the directorites that ConfigurationManager gives me (according to this post) but didn't find any track of this CustomSettings.

那么,保存此自定义设置文件和如何保存自定义设置文件的窍门是什么?

So, what is the trick with saving this Customized Settings Files and How to save Customized Settings Files?

推荐答案

好,现在我有一个正确的答案.一切正常,可以在dll文件下创建此自定义设置.

Ok, now I've got a right answer. Everything is OK that this custom settings were created under the dll file.

问题出在这个问题上 Application.UserAppDataPath奇怪的行为

The problem is with this questionApplication.UserAppDataPath strange behaviour

如果使用自动生成和修订版本号的AssemblyVersion并在AseemblyInfo.cs中具有AssemblyFileVersion,例如使用此dll的exe,则Application.UserAppDataPath将抛出ArgumentException路径中的非法字符". Application.UserAppDataPath用于构建此配置文件的路径以保存此CustomSettings.

If one have AssemblyVersion with automatic Build and Revision Numbers and have AssemblyFileVersion in AseemblyInfo.cs, say, of exe that uses this dll, then Application.UserAppDataPath will throw ArgumentException "Illegal characters in path." Application.UserAppDataPath is used to build path to this config file to save this CustomSettings.

但是ApplicationSettingsBase只是吃掉了内部发生的所有异常,因此文件没有保存,甚至没有人想到exe的AseemblyInfo.cs中的AssemblyFileVersion ...

But ApplicationSettingsBase just eats all exceptions that happens inside, so the file is just not saved and nobody could even think about AssemblyFileVersion in AseemblyInfo.cs of exe...

我的天哪...为此功能奋战了8个小时...

Ohhh my god... 8 hours of fighting with this ... feature...

这篇关于如何使用Properties.CustomSettings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:08