.NET CORE 能读到的配置文件为App.config,因为.NET CORE 属于控制台应用程序,所以新建一个App.config
.NET FRAMEWORK的web.config 是读不到的App.config的内容,像以前一样
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Sys" providerName="SqlServer" connectionString="server=.;uid=sa;pwd=123456;database=test" />
</connectionStrings>
<appSettings>
<add key="sqlite" value="test.db3"/>
</appSettings>
</configuration>
- 因为.NET CORE 不带有
ConfigurationManager
类,所以要在NuGet上安装System.Configuration.ConfigurationManager
,之后像.NET FRAMEWORK 读取配置文件一样读取配置
var sqlite = ConfigurationManager.AppSettings["sqlite"];