.NET 我的应用程序设置保存在哪里

发布于 2024-12-22 09:20:41 字数 950 浏览 2 评论 0原文

我很抱歉这会很冗长。但我觉得了解我所做的事情会更好地帮助一些人回答我的问题。

我一直致力于将应用程序和用户设置添加到我一直放在一起的项目中。好吧,实际上我已经完成了任务,编写了一个文件开关验证类,它更新用户设置或根据适当的文件开关重置它们,并针对无效、重复或有效的开关触发事件。

所有这些都运行良好。

当谈到我的编码时,我一直有这种学习障碍,我需要准确地理解某些东西是如何工作的,然后才能舒服地使用它。我喜欢 Visual Studio 为我所做的所有事情,但只要有可能,我就会忍不住查看黑匣子。

话虽这么说,我开始使用 .settings 文件添加了我需要的设置,将所有测试的所有内容都连接起来,就像我预期的那样。当然,它生成了完美的 cs 文件和 app.config 文件。

我不太喜欢这样,因为设计器文件不是来自 T4 代码生成工具,所以我无法控制包装类的静态实例是 .Default (我只是不喜欢它在我的代码中读取的方式) ....

所以我从设计器文件中删除了整个类,将其添加到我自己的cs文件中,进行了我想要的修改,并删除了cs和设计器文件以及.settings文件。 Ran 的东西仍然工作正常。

然后,为了确保它正确地拾取东西,我向类添加了一个附加设置,其中包含所有正确的属性等,果然它出现在我的代码中并且工作得很好。我可以重置、保存等,就像从原始 .settings 文件生成的那些设置一样。

但是...

我注意到app.config没有反映新值,在我的测试中它似乎也没有反映原始用户设置的更改。

现在我可能完全错过了一些东西,但是......

我可以抓住可执行文件运行它来查看默认设置。然后使用各种用户设置修饰符开关运行它,查看适当的设置。在没有开关的情况下再次运行它,并查看相同的用户设置,但可执行文件的目录中没有生成 app.config 或任何其他文件。顺便说一句,没有任何东西成为嵌入式资源。

最后我的问题是:

我想知道这些价值观到底在哪里被保留?

I apologize this is going to be long winded. But I feel an understand of what I've done will better help some answer my question.

I've been working on adding application and user settings to a project I've been putting together. Well actually I've completed the task, written a file switch validation class that updates the user settings or resets them per the appropriate file switches and fires events for invalid, duplicate, or valid switches.

All of that is working great.

When it comes to my coding I have always had this learning disability where I need to understand exactly how something works before I can feel comfortable using it. I love all the stuff that Visual Studio does for me but I can't resist looking in the black box when I can.

That being said I started out using a .settings file added the settings i needed wired everything up everything tested like i expected. It of course generated the cs files and the app.config file perfect.

I didn't really like that since the designer file is not from a T4 code generation tool so I could not control that the static instance of the wrapper class is .Default (I just didn't like the way it reads in my code)....

So I ripped the entire class out of the designer file added it to my own cs file, made the modifications I wanted and deleted the cs and designer files and the .settings files. Ran things still working solid.

Then to make sure it was picking things up properly I added an additional setting to the class with all the proper attributes etc and sure enough it showed up in my code and worked just fine. I could reset, save etc just like those settings that had been generated from the original .settings file.

However...

I noticed that the app.config did not reflect the new value, nor did it seem to reflect the changes of the original user settings in my testing.

Now it's possible that I'm completely missing something but...

I can snag JUST the executable run it see the default settings. Then Run it with various user setting modifier switches see the appropriate settings. Run it again without the switches and see the same user settings yet there is no app.config or any other file generated in the directory with the executable. Nothing was made an embedded resource either by the way.

So finally to my question:

I'm wondering where in the heck are these values being persisted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芯好空 2024-12-29 09:20:41

检查本地 appdata 目录 (C:\Documents and Settings\USERNAME\Local Settings\Application data\YOURPROJECTNAME\YOURASSEMBLY\ASSEMBLYVERSION\YOURFILE.config)。另请参阅 MSDN,尤其是设置文件位置 设置持久性 部分中的段落。

Check local appdata directory (C:\Documents and Settings\USERNAME\Local Settings\Application data\YOURPROJECTNAME\YOURASSEMBLY\ASSEMBLYVERSION\YOURFILE.config). Also consult MSDN, especially Settings File Locations paragraph in Settings Persistence section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文