我正在使用AppSettings的"文件"属性,但我收到此错误
根元素必须与引用文件的部分名称'appSettings'匹配
好吧,我在我的Windows项目中添加了ClassLibrary1.dll和ClassLibrary1.dll.config.Ny windows应用程序有自己的应用程序app.config
<configuration>
<appSettings file="ClassLibrary1.dll.config">
<add key="main" value="main"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
谢谢你提前
您的外部文件必须如下所示:
<?xml version="1.0"?>
<appSettings>
<add key="main" value="main"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
与使用时不同configSource,使用file属性时不能有配置节点.我甚至不能100%确定你可以使用带有configSource属性的配置节点,我总是匹配正在外化的根节点.有关详细信息,请参阅MSDN文档:http://msdn.microsoft.com/en-us/library/ms228154.aspx
此外,我从未试图像你在这里那样引用程序集配置文件.我想知道这可能会导致问题吗?尝试仅将appSettings节点提取到另一个配置文件,看看是否能解决问题.
编辑:这个外部文件(我们称之为appSettings_external.config)可以用两种方式:
app.config :(设置合并)
<?xml version="1.0"?>
<configuration>
<appSettings file="appSettings_external.config">
<add key="main" value="main"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
app.config :(设置仅从外部配置中提取)
<?xml version="1.0"?>
<configuration>
<appSettings configSource="appSettings_external.config" />
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8242 次 |
| 最近记录: |