问题描述
我曾经像这样为 ConfigurationBuilder
指定应用程序基本路径:
public Startup(IApplicationEnvironment appEnv){var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath).AddJsonFile("config.json").AddEnvironmentVariables();配置 = configurationBuilder.Build();}
但是,从 beta8 开始,ConfigurationBuilder
的构造函数不再接受应用程序基本路径参数,并且现在抛出异常.
如何指定基本路径?
如果我们看一下 ConfigurationBuilder
的源代码,我们可以看到构造函数不再接受代表应用程序基路径的字符串.相反,我们必须使用 IConfigurationBuilder 接口上的 >SetBasePath() 扩展方法 来指定它:
public Startup(IApplicationEnvironment appEnv){var configurationBuilder = new ConfigurationBuilder().SetBasePath(appEnv.ApplicationBasePath).AddJsonFile("config.json").AddEnvironmentVariables();配置 = configurationBuilder.Build();}
可以找到特定的提交"> I used to specify the application base path for the However, as of beta8, the constructor of How can I specify the base path? If we look at the source code of The particular commit can be found here. 这篇关于在 beta8 中的 ConfigurationBuilder 中指定应用程序基路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!ConfigurationBuilder
like this: public Startup(IApplicationEnvironment appEnv)
{
var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = configurationBuilder.Build();
}
ConfigurationBuilder
does not take an application base path argument anymore and it throws an exception now. 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();
}