控制台应用程序的配置 .net Core 2.0 [英] Configuration for console apps .net Core 2.0

查看:29
本文介绍了控制台应用程序的配置 .net Core 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .net Core 1 中,我们可以这样做:

In .net Core 1 we could do this:

IConfiguration config =  new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", true, true)
                .Build();

这提供了我们可以在控制台应用程序中使用的配置对象.

And that gave use the Configuration object that we could then use in our console app.

.net core 2.0 的所有示例似乎都是根据创建 Asp.Net core 配置的新方式量身定制的.

All examples for .net core 2.0 seem to be tailored to the new way Asp.Net core config is created.

为控制台应用创建配置的方法是什么?

What is the way to create configurations for console apps?

更新:此问题与 Asp.net 核心无关.编辑时请不要添加asp.net core标签.

Update: this question is not related to Asp.net core. Please do not add asp.net core tags when editing.

推荐答案

似乎没有变化,正如 Jehof 所说.

It seems there is no change, as Jehof says.

ConfigurationBuilder 在它自己的包中,正如 Jeroen Mostert 所说.

ConfigurationBuilder is in its own package, as Jeroen Mostert says.

但请确保您还有 Microsoft.Extensions.Configuration.Json 包,其中 .AddJsonFile() 扩展位于其中.

But make sure you also have the Microsoft.Extensions.Configuration.Json package, where the .AddJsonFile() extension lives.

总而言之,您需要以下两个 NuGet 包:

In summary, you need the following two NuGet packages:

  • Microsoft.Extensions.Configuration (2.0.0)
  • Microsoft.Extensions.Configuration.Json (2.0.0)

这篇关于控制台应用程序的配置 .net Core 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆