当我刚刚有一个 app.config 时,每次我尝试 ConfigurationManager.AppSettings[0] 或 ConfigurationManager.AppSettings["keyName"] 时,我都会得到一个空值。所以我尝试使用一个 *.settings 文件,它为我创建了一个看起来像这样的 app.config
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="IndexLoader.IndexLoader" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<IndexLoader.IndexLoader>
<setting name="ConnectionString" serializeAs="String">
<value>INITIAL CATALOG=xxx;DATA SOURCE=xxx;User ID=xxx;Password=xxx;Application Name=xxx;</value>
</setting>
</IndexLoader.IndexLoader>
</applicationSettings>
</configuration>
现在如何使用 C# 读取此连接字符串?
该解决方案有多个项目,其中许多都有配置文件。有没有办法指定我希望使用代码项目中的配置文件?