问题描述
按照的丰富信息,我们如何获得外部.config工作?我尝试了一个外部appSettings文件使用的相同设置,但是无法找到自定义部分的文件。
following the wealth of information found here how can we get an external .config to work? I've tried the same setup I would use for an external appSettings file, but it is unable to find the file for my custom section.
<configSections>
...
<section name="CustomSettings" type="Fully.Qualified.TypeName.CustomSettings, AssemblyName" />
</configSections>
<!-- this works -->
<CustomSettings attrib1="val1" attrib2="val2" .../>
但是...
<!--this does not work-->
<CustomSettings configSource="someExternalFile.config"/>
其中someExternalFile.config将包含
where someExternalFile.config would contain
<CustomSettings attrib1="val1" attrib2="val2" .../>
任何想法?
推荐答案
实际文件必须相对于项目输出文件夹放置(默认为\bin\debug或bin\Release
The actual file, must be placed relative to the project output folder (by default "\bin\debug" or "bin\Release"
此外,项目树中的文件,查看文件的属性,并确保复制到输出目录设置设置为始终复制或复制如果更新
Also, The file in your project tree, look at the properties of the file, and make sure the "Copy to Output Directory" setting is set to "Copy Always" or "Copy if Newer"
编辑:确保单独的配置文件有一个xml Element头,整个文件内容应该如下:
make sure the separate config file has an xml Element header. The entire file contents should read as follows:
<?xml version="1.0" encoding="utf-8" ?>
<CustomSettings attrib1="val1" attrib2="val2" .../>
这篇关于如何为.NET中的自定义配置节启用configSource属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!