如何启用configSource在.NET属性自定义配置节? [英] How to enable configSource attribute for Custom Configuration Section in .NET?

查看:515
本文介绍了如何启用configSource在.NET属性自定义配置节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的丰富的信息在这里找到 的,我们怎样才能得到一个外部的.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" .../>

不过...

however...

<!--this does not work-->
<CustomSettings configSource="someExternalFile.config"/>

在这里someExternalFile.config将包含

where someExternalFile.config would contain

<CustomSettings attrib1="val1" attrib2="val2" .../>

什么想法?

推荐答案

实际文件,必须相对放置到项目输出文件夹(默认为\斌\调试或BIN \发布

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" .../>

这篇关于如何启用configSource在.NET属性自定义配置节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆