DotNet Core 2 控制台应用程序配置
DotNet Core 2 Console Application Configuration
核心 1.x 配置已在此处得到解答
不幸的是,核心 2.0.0 API 和体系结构略有变化,the looks of this article 它现在在启动时使用依赖注入 class(在 WebAPI 基于项目)分配更简单。
但我不确定如何在控制台应用程序上执行此操作,因为没有底层 DI。当我尝试使用下面的代码时 none 方法存在于新的 2.0.0
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true) -ERROR
.AddJsonFile($"appsettings.{environmentName}.json", true, true) -ERROR
.AddEnvironmentVariables(); -ERROR
有人知道如何将 appsettings.json
添加到 ConfigurationBuilder 中吗?
原来我必须手动添加这个包,其中包含 AddJsonFile 扩展 - 出于某种原因,Intellisense 不建议安装这个包,因为它与其他东西一样。
dependencies {
"Microsoft.Extensions.Configuration.Json": "2.0.0"
}
核心 1.x 配置已在此处得到解答
不幸的是,核心 2.0.0 API 和体系结构略有变化,the looks of this article 它现在在启动时使用依赖注入 class(在 WebAPI 基于项目)分配更简单。
但我不确定如何在控制台应用程序上执行此操作,因为没有底层 DI。当我尝试使用下面的代码时 none 方法存在于新的 2.0.0
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true) -ERROR
.AddJsonFile($"appsettings.{environmentName}.json", true, true) -ERROR
.AddEnvironmentVariables(); -ERROR
有人知道如何将 appsettings.json
添加到 ConfigurationBuilder 中吗?
原来我必须手动添加这个包,其中包含 AddJsonFile 扩展 - 出于某种原因,Intellisense 不建议安装这个包,因为它与其他东西一样。
dependencies {
"Microsoft.Extensions.Configuration.Json": "2.0.0"
}