在网里。config文件。NET-application的一些配置部分,如appSettings和connectionStrings,支持属性文件和configSource。
使用file-属性和configsource -属性有什么区别?什么时候应该使用哪个属性,可以同时使用两个属性吗?
<?xml version="1.0"?>
<configuration>
<appSettings file="AppSettings.config">
</appSettings>
<connectionStrings configSource="ConnectionStrings.config">
</connectionStrings>
<!-- ... -->
</configuration>
文件属性
Specifies a relative path to an external file that contains custom application configuration settings
specific to the appSettings section
will merge (and override) settings in the .config file
will not cause web application to restart when modifying the specified file
http://msdn.microsoft.com/en-US/library/ms228154(v=vs.100).aspx
Using the Configuration.AppSettings.Settings.Add API will result in all settings being merged back into the main .config on a Configuration.Save call.
since .NET 1.1
Exception is not thrown if file does not exist.
configSource属性
can apply to most sections of a configuration file, not just appSettings
will override the entire section with the external file, no merging
CAN cause web application to restart
http://msdn.microsoft.com/en-US/library/system.configuration.sectioninformation.configsource(v=vs.100).aspx
Using the Configuration.AppSettings.Settings.Add API will result in all settings being added to the file specified in configSource on a Configuration.Save call.
since .NET 2.0
System.Configuration.ConfigurationErrorsException is thrown if config source file does not exist.
file属性指定一个包含自定义设置的外部文件,就像您在web的appSettings条目中所做的那样。配置文件。
同时,configSource属性中指定的外部文件包含您为其声明configSource的部分的设置。例如,如果您使用pages部分的configSource属性,那么外部文件将包含pages部分的设置。
中指定的外部配置中声明的自定义设置
文件属性将与appSettings中的设置合并
部分。配置文件。同时,configSource . xml文件
不支持合并,这意味着你将不得不移动整个
部分设置到外部文件。
http://www.codeproject.com/Messages/1463547/Re-difference-between-configSource-and-file-attrib.aspx