C# 应用程序设置可以以 XML (protobuf-net) 以外的格式序列化吗?
C# 应用程序设置可以以 XML 以外的格式序列化吗?我找不到任何可以支持这一理论的东西。具体来说,我尝试保存的格式是通过 protobuf-net 的协议缓冲区格式。
如果我不能,并且需要“手动”写入保存文件,如何获取 Visual Studio (2010) 用于保存应用程序设置的路径?我可以得到路径
...\AppData\Local\${公司名称}\${应用程序名称}\
问题是 Visual Studio 实际上将我的应用程序设置保存为类似的内容
...\AppData\Local\${公司名称}\${应用程序名称}.exe_Url_uzttbld0ofvuokf2y4ynfn05v334i4tp\
我希望我的 xml 设置文件和 protobuf-net 文件出现在同一位置。
Can c# application settings be serialized in a format besides XML? I can't find anything which would support the theory that one can. Specifically, the format I'm trying to save in is the protocol buffer format via protobuf-net.
If I can't, and need to write to a save file "by hand", how do I get the path that Visual Studio (2010) is using to save the application settings to? I can get the path
...\AppData\Local\${Company Name}\${Application Name}\
The problem is that Visual Studio is actually saving my application settings to something like
...\AppData\Local\${Company Name}\${Application Name}.exe_Url_uzttbld0ofvuokf2y4ynfn05v334i4tp\
I would like for the my xml settings file and my protobuf-net file to appear in the same location.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(假设您正在编写 WinForms 或 WPF 应用程序。Web 应用程序的规则有所不同)
您可以通过
ExeConfigurationFileMap
类。但请注意,您的代码可能没有对所有这些位置的写访问权限,具体取决于应用程序的安装方式。您无法更改标准配置文件的格式。
System.Configuration
命名空间中的类仅理解 XML 配置文件。您必须为 protobuf-net 文件编写自己的序列化/反序列化支持,并且如果您想要/需要使用 System.Configuration 命名空间,则必须将文件的内容与标准配置文件。(Assuming you are writing WinForms or WPF application. The rules for web apps are different)
You can find the location of the configuration files for your executable through the
ExeConfigurationFileMap
class. Note though, that your code might not have write access to all of these locations, depending on how the application was installed.you cannot change the format of the standard configuration file. The classes in the
System.Configuration
namespace only understand XML configuration files. You will have to write your own serialization/deserialization support for the protobuf-net file, and if you want/need to use theSystem.Configuration
namespace, you will have to synchronize the content of your file with the standard config file.我不会触及主配置本身,但是您可以简单地将路径存储为设置,即
然后在运行时您可以使用常规设置框架来获取文件路径,然后从那里。
这应该可行 - 尽管我不确定它是经典用例;人们通常喜欢他们的配置设置易于通过记事本读取和编辑。
I wouldn't touch the main config itself, however you can trivially store a path as a setting, i.e.
Then at runtime you could use the regular settings framework to get the file-path, and then deserialize from there.
That should work - although I'm not sure it is the classic use-case; people generally like their configuration settings to be human-readable and editable via notepad.