用dotnet run运行ASP.NET Core站点时,出现如下的错误:
Startup.cs(24,18): error CS1061: 'IConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no extension method 'AddJsonFile' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)
Startup.cs中的对应代码如下:
public Startup(IHostingEnvironment hostingEnv) { IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(hostingEnv.ContentRootPath) .AddJsonFile("config.json", false); Configuration = builder.Build(); }
在 project.json 文件的 dependencies 中添加如下的配置可解决问题:
"Microsoft.Extensions.Configuration.Json": "1.0.0-*"