如何在.NET 中启用自定义配置节的 configSource 属性?
根据此处找到的大量信息,我们如何才能让外部 .config 工作? 我已经尝试了与外部 appSettings 文件相同的设置,但无法找到我的自定义部分的文件。
<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 会包含
<CustomSettings attrib1="val1" attrib2="val2" .../>
任何想法吗?
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" .../>
however...
<!--this does not work-->
<CustomSettings configSource="someExternalFile.config"/>
where someExternalFile.config would contain
<CustomSettings attrib1="val1" attrib2="val2" .../>
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际文件必须相对于项目输出文件夹放置(默认情况下为“\bin\debug”或“bin\Release”
此外,项目树中的文件,查看文件的属性,并确保“ “复制到输出目录”设置设置为“始终复制”或“如果较新则复制”
编辑:确保单独的配置文件具有 xml 元素标头。整个文件内容应如下所示:
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"
EDIT: make sure the separate config file has an xml Element header. The entire file contents should read as follows: