应用程序设置保存在哪里? [英] Where are application settings saved?

查看:352
本文介绍了应用程序设置保存在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试存储一些持久性应用程序数据,因此我已经通过R单击它,选择属性,然后选择设置"选项卡并手动输入设置名称,类型,范围和值来将设置添加到项目中

I am trying to store some persistent application data so I've added a setting to the project by R-Clicking on it, selecting properties, then Settings tab and manually entering settings name, Type, Scope and Value

运行代码时,我会读取如下设置:

When I run the code, I read settings like this:

lastRunTime = My.Settings.LastRunTime

并像这样设置它:

My.Settings.LastRunTime = lastRunTime

我实际上在哪里可以看到新设置?因为为了上帝的爱,我看不到它在更新环境.创建该设置时,app.config具有原始设置值.那我在哪里可以看到呢?

Where can I actually see the new setting? Because for the love of God, I cannot see where it is updating the setting. app.config has the original setting value when I created that setting. So where can I see it?

当我运行代码时,我看到它对其进行了更新,并且下次我运行该应用程序时,新值仍然存在,因此我知道它会将其存储在某个地方.但是在哪里?

When I run the code, I see it updates it and the next time I run the app the new value persists, so I know it stores it somewhere. But where?

推荐答案

.NET必须做一些特别的事情,它必须向您保证另一个程序也恰好具有"LastRuntime"设置不会覆盖为程序存储的值.为此,它将user.config文件存储在很难找到的目录中.它有一个怪异的名字,例如

.NET has to do something special, it has to give you a guarantee that another program that also happens to have a "LastRuntime" setting doesn't overwrite the value that's stored for your program. To do that, it stores a user.config file in a directory that's hard to find back. It has a weirdo name, like

C:\ Users \ username \ AppData \ Local \ WindowsFormsApplication1 \ WindowsFormsApplication1._Url_twchbbo4atpsvjpauzkgkvesu5bh2aul \ 1.0.0.0 \ user.config

C:\Users\username\AppData\Local\WindowsFormsApplication1\WindowsFormsApplication1._Url_twchbbo4atpsvjpauzkgkvesu5bh2aul\1.0.0.0\user.config

请注意项目名称是如何包含在路径中的,这是找到它的一种方法.名称的难以言喻的部分是 hash ,它是由项目的各种属性创建的,这些属性使您的应用程序具有足够的独特性,即使名称匹配也不会与其他.NET程序发生冲突.例如您的产品名称,公司名称,exe名称等.

Note how the project name is part of the path, that's one way to find it back. The unspeakable part of the name is a hash, created from various properties of your project that make your app unique enough to not collide with another .NET program, even if the name matches. Like your product name, company name, exe name, etcetera.

请注意反之亦然,更改此类属性会使您丢失user.config文件.因此,如果"LastRuntime"是某种许可证计量值,那么使用设置不是最好的主意.

Note how the converse is true as well, changing such a property makes you lose your user.config file. So if "LastRuntime" is some kind of license metering value then using a setting isn't the best idea.

这篇关于应用程序设置保存在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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