设置文件与 app.config

发布于 2024-08-26 14:27:34 字数 385 浏览 6 评论 0原文

可能的重复:
app.config 之间有什么区别文件和 XYZ.settings 文件?

我不太了解设置和配置文件之间的交互/差异。如果我向设置文件添加一个条目,它也会添加到 app.config 中。这是否意味着更改 app.config 中的值将更新设置?如果没有,如何更新实时应用程序中的设置?使用设置文件而不是直接将内容放入 app.config 的一般目的是什么?

Possible Duplicate:
What is the difference between app.config file and XYZ.settings file?

I'm not really understanding the interaction/differences between settings and config files. If I add an entry to the settings file, it gets added to the app.config as well. Does this mean that changing the value in the app.config will update the settings? If not, how do I update settings in a live application? What's the general purpose of using a settings file instead of putting things directly in app.config?

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

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

发布评论

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

评论(1

じ违心 2024-09-02 14:27:34

通过环顾四周,我发现设置文件和设计器似乎为配置文件提供了一种包装器。设置设计器控制进入配置文件的一些值,但也会修改 Properties 目录中的 .settings 文件,并更改 Settings.Designer.cs 中生成的代码> 文件。

请注意,在配置文件中,值没有任何类型,但在 .settings 文件中,它们有任何类型。现在打开Settings.Designer.cs。您将看到那里生成的代码从您的配置文件中获取值,并将它们转换为正确的类型,如 .settings 文件或设置设计器中指定的那样。因此它为配置文件中的值提供了一个类型安全的接口。如果您更改配置文件中的值,那么下次您进入设置设计器时,它会询问您是否要更新 .settings 以反映这些更改。

因此,为了回答您的问题,部署应用程序后,您可以更改配置文件中的值,只要它可以转换为正确的类型,否则我猜它会在 Settings.Designer.cs 中失败。我能看到的唯一目的似乎是类型安全和设计者在处理配置文件的 XML 时的便利性。

另外,请记住,由于配置不是版本控制文件,因此安装程序不会在客户端计算机上更新它们。它不允许它践踏任何用户更改。因此,一旦部署,如果您将自己的更改放入用户需要的配置中,他们将必须手动复制更改。

From what I can tell by looking around, it seems the settings file and designer provide a sort of wrapper for the config file. The settings designer controls some values that go into the config file, but also modifies the .settings file in your Properties directory, and changes the generated code in your Settings.Designer.cs file.

Notice that in the config file, values don't have any types, but in the .settings file, they do. Now open Settings.Designer.cs. You'll see that the code generated there takes values out of your config file, and casts them to the proper types, as specified in your .settings file, or the settings designer. So it's providing a type safe interface to values in your config file. If you change a value in your config file, then the next time you go to the settings designer, it will ask you if you would like to update .settings to reflect those changes.

So to answer your question, once the app is deployed, you can change the value in the config file as long as it can be cast to the proper type, otherwise I'm guessing it will fail in Settings.Designer.cs. The only purpose that I can see seems to be type safety and convenience of a designer over handling the XML of the config file.

Also as an aside, remember that because config is not a versioned file, installers will not update them on a client's machine. It won't allow it to stomp on any user changes. So once it's deployed, if you put your own changes into the config that users will need, they will have to copy the changes over manually.

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