问题描述
根据在此处找到的大量信息,我们如何获得外部 .配置工作?我已经尝试了用于外部 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 元素标头.整个文件内容应如下所示:
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 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!