Possible Duplicate:
What is the difference between app.config file and XYZ.settings file?可能重复:app.config文件和XYZ之间的区别是什么?设置文件?
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?
我没有真正理解设置和配置文件之间的交互/差异。如果我向设置文件添加一个条目,它也会被添加到app.config中。这是否意味着更改app.config中的值将更新设置?如果没有,如何在实时应用程序中更新设置?使用设置文件而不是将内容直接放入app.config的一般目的是什么?
1 个解决方案
#1
16
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.
根据我的观察,似乎设置文件和设计器为配置文件提供了一种包装。设置设计器控制进入配置文件的一些值,但也修改属性目录中的.settings文件,并更改Settings.Designer中生成的代码。cs文件。
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.
注意,在配置文件中,值没有任何类型,但是在.settings文件中,它们有。现在Settings.Designer.cs开放。您将看到生成的代码从配置文件中取出值,并将它们转换为适当的类型,如.settings文件中指定的,或设置设计器。因此,它为配置文件中的值提供了一个类型安全的接口。如果您在配置文件中更改了一个值,那么下次访问设置设计器时,它将询问您是否希望更新.settings以反映这些更改。
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.
为了回答你的问题,一旦应用被部署,你可以修改配置文件中的值,只要它可以被转换为正确的类型,否则我猜它会在Settings.Designer.cs中失败。我能看到的唯一目的似乎是设计器在处理配置文件的XML时的类型安全性和方便性。
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.
另外,请记住,由于配置不是版本化的文件,安装程序不会在客户端机器上更新它们。它不允许用户更改。因此,一旦部署完毕,如果您将自己的更改放入用户需要的配置中,他们将不得不手动复制这些更改。
#1
16
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.
根据我的观察,似乎设置文件和设计器为配置文件提供了一种包装。设置设计器控制进入配置文件的一些值,但也修改属性目录中的.settings文件,并更改Settings.Designer中生成的代码。cs文件。
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.
注意,在配置文件中,值没有任何类型,但是在.settings文件中,它们有。现在Settings.Designer.cs开放。您将看到生成的代码从配置文件中取出值,并将它们转换为适当的类型,如.settings文件中指定的,或设置设计器。因此,它为配置文件中的值提供了一个类型安全的接口。如果您在配置文件中更改了一个值,那么下次访问设置设计器时,它将询问您是否希望更新.settings以反映这些更改。
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.
为了回答你的问题,一旦应用被部署,你可以修改配置文件中的值,只要它可以被转换为正确的类型,否则我猜它会在Settings.Designer.cs中失败。我能看到的唯一目的似乎是设计器在处理配置文件的XML时的类型安全性和方便性。
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.
另外,请记住,由于配置不是版本化的文件,安装程序不会在客户端机器上更新它们。它不允许用户更改。因此,一旦部署完毕,如果您将自己的更改放入用户需要的配置中,他们将不得不手动复制这些更改。