Properties.Settings 不是我期望的值

发布于 2024-12-03 00:17:02 字数 688 浏览 1 评论 0原文

我的项目中有一个设置,当从代码引用时(即我将鼠标悬停在可以看到该值的对象上),该设置与 Properties.Settings 文件中的设置不同。这是一个旧值。我可以转到设置编辑器并将值更新为其他值,但旧值仍然存在。 如果我使用 .Properties.Settings.Default.Save() 方法,设置将被更改,但当我停止调试时,该更改不会反映在编辑器中。 我可以在文本编辑器中打开 Settings.settings 文件,它会显示与 VS 中的设置编辑器中相同的内容。 我还可以在我的计算机上搜索其他 Settings.settings 文件,并且只显示一个文件(其他文件确实出现,但它们显然不相关,修改了旧日期,并且不会具有相同的设置名称。)

该文件在哪里以及为什么在值与我认为应该的值不同吗?

编辑:

我无法再次同步原始设置变量,因此我使用设置 GUI 界面创建了一个新的设置变量。而且它似乎正在正确传播。每个人建议我查看的所有文件都有我想要的设置变量的值,但是当我运行调试会话并查看同一个变量时,它是一些我无法跟踪的旧值。

现在回想起来,大约 1.5 个月前,我在另一个变量上遇到了类似的问题,但当时我并没有深入研究。我也必须做同样的事情。创建一个新的类似名称的变量,删除旧变量并移动一个。

编辑2:

更改设置变量名称并让VS通过程序自行传播该更改似乎也是一种硬重启。

I have a setting in my project that, when referenced from code (i.e. i hover over the object I can see the value), is not the same as what is in the Properties.Settings file. It is an old value. I can go to the settings editor and update the value to something else but the old value persists.
If I use .Properties.Settings.Default.Save() method the setting will be changed but that change is not reflected in the editor when I stop debugging.
I can open up the Settings.settings file in a text editor and it will show me the same thing as what is in the settings editor in VS.
I can also search my computer for other Settings.settings files and only that one shows up (others do show up but they are clearly unrelated, have old date modifieds and would not have the same setting name.)

Where is this file and why is the value different than what I think it should be?

Edit:

I could not get my original setting variable to be synced up again so I created a new setting variable with the setting GUI interface. And it seems to be propagating through properly. All of the files everyone was suggesting I look in had the values I wanted my setting variable to be but when I ran a debug session and looked at the same variable it was some old value that I could not trace.

Now that I think back, about 1.5 months ago I had experienced a similar problem with another variable but I didn't dig this deep that time. I had to do the same thing. Make a new similarly named variable, delete the old one and move one.

Edit 2:

Changing the setting variable name and letting VS propagate that change through the program on it's own seems to be a kind of hard reboot too.

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

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

发布评论

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

评论(4

世俗缘 2024-12-10 00:17:02

您还没有找到设置文件。它的名称不是Setting.settings,而是一个项目文件。它被命名为“user.config”并存储在一个具有奇怪名称的目录中,例如:

C:\Users\HPassant\AppData\Local\MyCompany\
WindowsFormsApplication1._Url_ghbcotszbdzyqv2ovpc1keo1yctxkcw5\1.0.0.0

其中“HPassant”是用户名,“MyCompany”是 [AssemblyCompany] 属性,“WindowsFormsApplication1”是项目名称,接下来是各种值的哈希值,然后是[程序集版本]。您可以使用 Reflector 或 ILSpy 查看算法,查看 ClientConfigPaths 类构造函数。

You haven't found the settings file. It is not named Setting.settings, that's a project file. It is named "user.config" and stored in a directory with a strange name like:

C:\Users\HPassant\AppData\Local\MyCompany\
WindowsFormsApplication1._Url_ghbcotszbdzyqv2ovpc1keo1yctxkcw5\1.0.0.0

Where "HPassant" is the user name, "MyCompany" is the [AssemblyCompany] attribute, "WindowsFormsApplication1" is the project name, followed by a hash of various values, followed by the [AssemblyVersion]. You can see the algorithm with Reflector or ILSpy, look at the ClientConfigPaths class constructor.

只为一人 2024-12-10 00:17:02

默认的 Properties.Settings 值将被 app.config 中的值覆盖。

对于已部署的应用程序,app.config 会重命名为 YourApplicationName.exe.config,这是处理应用程序参数配置的推荐方法。

The default Properties.Settings value is overridden by the values in app.config.

In case of a deployed application app.config is renamed to YourApplicationName.exe.config and is the recommended way to handle configuration of application parameters.

阳光下的泡沫是彩色的 2024-12-10 00:17:02

我将设置范围从用户更改为应用程序,解决了我的问题。

I changed the Settings Scope from User to Application that solved my problem.

糖果控 2024-12-10 00:17:02

当您保存设置时,设置将保存到 YourApplicationName.exe.config,如 @Albin Sunnanbo 所解释的。

因此,当您调用 Settings.Default.Save() 时,您正在更改此文件,而不是项目中的 app.config 。您的二进制文件不了解 app.config,它们只关心已部署的副本。

设置变量有多个范围。如果将范围设置为“应用程序”,则您将只有该值的一个“实例”。如果将其设置为“用户”,则每个唯一的 Windows 用户都将拥有自己的设置副本。

您在 app.config / Properties.Settings 中提供的内容是默认值。当您调用 Settings.Default.Save() 时,它们将在 YourApplicationName.exe.config 中被覆盖。

调试时,您将在 /bin/debug 文件夹中找到 YourApplicationName.exe.config。看看那里,您将看到应用程序中的值与此文件中的值相同,而不是 app.config 中的值。

When you save your settings, the settings are saved to the YourApplicationName.exe.config, as @Albin Sunnanbo explained.

So when you call Settings.Default.Save() you are changing this file, not app.config in your project. Your binaries have no knowledge of app.config, they only care about the deployed copy.

There are multiple scopes for a settings variable. If you set the scope to Application, you will only have one 'instance' of this value. If you set it to User, each unique windows user will have its own copy of the settings.

What you provide in app.config / Properties.Settings are default values. They will be overwritten in YourApplicationName.exe.config when you call Settings.Default.Save().

When debugging, you will find the YourApplicationName.exe.config in your /bin/debug folder. Look there, and you will see that the values in your application are the same as in this file, not the ones in app.config.

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