在beta8中的ConfigurationBuilder中指定应用程序基本路径 [英] Specify the application base path in ConfigurationBuilder in beta8

查看:405
本文介绍了在beta8中的ConfigurationBuilder中指定应用程序基本路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用来为 ConfigurationBuilder 指定应用程序基本路径,如下所示:

I used to specify the application base path for the ConfigurationBuilder like this:

public Startup(IApplicationEnvironment appEnv)
{
    var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();

    Configuration = configurationBuilder.Build();
}

但是,从beta8开始, ConfigurationBuilder 不再接受应用程序基路径参数,它现在抛出异常。

However, as of beta8, the constructor of ConfigurationBuilder does not take an application base path argument anymore and it throws an exception now.

如何指定基本路径?

推荐答案

请查看 的源代码, ConfigurationBuilder ,我们可以看到构造函数不再接受表示应用程序基本路径的字符串。相反,我们必须使用 <$界面上的 SetBasePath()扩展方法来指定它:

If we look at the source code of ConfigurationBuilder, we can see that the constructor no longer accepts a string representing the application base path. In stead, we have to use the SetBasePath() extension method on the IConfigurationBuilder interface to specify it:

public Startup(IApplicationEnvironment appEnv)
{
    var configurationBuilder = new ConfigurationBuilder()
        .SetBasePath(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();

    Configuration = configurationBuilder.Build();
}

可以找到特定的提交此处

这篇关于在beta8中的ConfigurationBuilder中指定应用程序基本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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