应用设置架构App Settings schema

包含自定义应用程序设置,如文件路径、XML Web service URL 或应用程序的任何其他自定义配置信息。Contains custom application settings, such as file paths, XML Web service URLs, or any other custom configuration information for an application.

<configuration> <configuration>
   <appSettings>   <appSettings>
     <add>     <add>
     <clear>     <clear>
     <remove>     <remove>

元素Element 描述Description
<appSettings> <appSettings> 包含 <add><clear><remove> 标记,用于控制应用程序设置。Contains <add>, <clear>, and <remove> tags to control application settings. 具有可选的“file”属性。Has an optional file attribute.
<add> <add> 定义设置。Defines a setting. <appSettings> 的子级。Child of <appSettings>. 需要“key”和“value”属性。Requires key and value attributes.
<clear> <clear> 清除所有设置。Clears all settings. <appSettings> 的子级。Child of <appSettings>. 不具有属性。Has no attributes.
<remove> <remove> 删除设置。Removes a setting. <appSettings> 的子级。Child of <appSettings>. 需要“key”属性。Requires a key attribute.

<appSettings> 元素<appSettings> element

此元素包含 <add><clear><remove> 标记,用于控制应用程序设置。This element contains <add>, <clear>, and <remove> tags to control application settings. 它定义“file”的一个可选属性。It defines an optional attribute for file.

<add> 元素<add> element

将自定义应用程序设置作为名称/值对添加到应用程序设置集合。Adds a custom application setting as a name/value pair to the application settings collection. 它定义“key”和“value”的属性。It defines attributes for key and value.

<clear> 元素<clear> element

删除对继承的自定义应用程序设置的所有引用,并仅允许由 <add> 元素(位于 <clear> 元素后)添加的引用。Removes all references to inherited custom application settings and allows only the references that are added by <add> elements following the <clear> element. 未定义任何属性。It defines no attributes.

<remove> 元素<remove> element

删除对应用程序设置集合中继承的自定义应用程序设置的引用。Removes a reference to an inherited custom application setting from the application settings collection. 定义“key”的属性。It defines an attribute for key.

示例Example

下面的示例演示外部应用程序设置文件 (custom.config),该文件定义自定义应用程序设置:The following example shows an external application settings file (custom.config) that defines a custom application setting:

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
  <add key="MyCustomSetting" value="MyCustomSettingValue" />
</appSettings>

下面的示例演示使用外部设置文件中的设置并自行设置应用程序设置的应用程序配置文件:The following example shows an application configuration file that consumes the setting in the external settings file and sets an application setting of its own:

<configuration>
  <appSettings file="custom.config">
    <add key="ApplicationName" value="MyApplication" />
  </appSettings>
</configuration>

请参阅See also