2017-10-11 49 views
0

我试图使用“文件”属性将appSettings config部分移至外部文件,并继续获取错误:错误“根元素必须与引用文件的部分的名称相匹配”,当根元素与部分的名称匹配时

System.Configuration.ConfigurationErrorsException : The root element must match the name of the section referencing the file, 'appSettings'

问题是外部文件中的根元素已经是'appSettings'。 使用根“配置”和自定义配置节试过了,它并没有帮助

外部文件Test.config低于

<?xml version="1.0" encoding="utf-8" ?> 
<appSettings> 
    <add key="URL" value="https://www.google.com" /> 
</appSettings> 

主要App.config文件

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/> 
    </configSections> 
    <specFlow> 
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --> 
    </specFlow> 
    <appSettings file="Test.config"/> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> 
</startup> 
</configuration> 

谁能帮我这个?

谢谢。

回答

0

对我来说这是一个路径问题。 visual studio的默认行为是不包含输出目录中的文件。我将每个版本的文件属性更改为“始终复制”,以确保您拥有最新的文件。如果您已将其添加到属性部分中的项目中,则文件引用应在路径中包含属性文件夹。

相关问题