将示例站点升级至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(); }
将 IApplicationEnvironment 改为 IHostingEnvironment ,修改后的代码如下:
public Startup(IHostingEnvironment hostingEnv) { IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(hostingEnv.ContentRootPath) .AddJsonFile("config.json", false); Configuration = builder.Build(); }