如何在.NET 中启用自定义配置节的 configSource 属性?

发布于 2024-07-11 12:33:49 字数 726 浏览 5 评论 0原文

根据此处找到的大量信息,我们如何才能让外部 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潜移默化 2024-07-18 12:33:49

实际文件必须相对于项目输出文件夹放置(默认情况下为“\bin\debug”或“bin\Release”

此外,项目树中的文件,查看文件的属性,并确保“ “复制到输出目录”设置设置为“始终复制”或“如果较新则复制”

编辑:确保单独的配置文件具有 xml 元素标头。整个文件内容应如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<CustomSettings attrib1="val1" attrib2="val2" .../>

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:

<?xml version="1.0" encoding="utf-8" ?>
<CustomSettings attrib1="val1" attrib2="val2" .../>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文