安装以下Nuget
软件包后,
https: //www.nuget.org/packages/Microsoft.Configuration.ConfigurationBuilders.Environment/ 在使用自定义配置生成器之前,
我们应该先注册。configbuilder
<configuration>
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection,
System.Configuration, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
restartOnExternalChanges="false" requirePermission="false" />
</configSections>
请参考我的优先获取ServiceID
from的配置。System Environment Variables
<configuration>
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection,
System.Configuration, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="Secrets" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</builders>
</configBuilders>
<appSettings configBuilders="Secrets">
<add key="ServiceID" value="ServiceID value from web.config" />
<add key="ServiceKey" value="Spotify" />
</appSettings>
<connectionStrings configBuilders="Secrets">
<add name="default" connectionString="Data Source=web.config/mydb.db" />
</connectionStrings>
ServiceID/ServiceKey
如果设置,将从系统环境变量中获取值。
如果问题仍然存在,请随时告诉我。