首页 新闻 会员 周边 捐助

升级至ASP.NET Core RC2,运行时找不到IApplicationEnvironment的问题

0
悬赏园豆:10 [已解决问题] 解决于 2016-05-18 10:05

将示例站点升级至ASP.NET Core RC2之后,dotnet run运行站点是出现如下的错误:

Startup.cs(20,24): error CS0246: The type or namespace name 'IApplicationEnvironment' could not be found (are you missing a using directive or an assembly reference?)

Startup.cs中对应的代码如下:

public Startup(IApplicationEnvironment appEnv)
{
    IConfigurationBuilder builder = new ConfigurationBuilder()
        .SetBasePath(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json", false);
    Configuration = builder.Build();
}
dudu的主页 dudu | 高人七级 | 园豆:29570
提问于:2016-05-17 17:22
< >
分享
最佳答案
0

将 IApplicationEnvironment 改为 IHostingEnvironment ,修改后的代码如下:

public Startup(IHostingEnvironment hostingEnv)
{
    IConfigurationBuilder builder = new ConfigurationBuilder()
        .SetBasePath(hostingEnv.ContentRootPath)
        .AddJsonFile("config.json", false);
    Configuration = builder.Build();
}
dudu | 高人七级 |园豆:29570 | 2016-05-17 18:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册