C# – Why does Visual Studio tell me that the AddJsonFile() method is not defined


I'm developing an ASP.NET 5 WebAPI project using VS Ultimate 2015 Preview. I'm trying to configure the app in this way (line numbers are just guides):

1 using Microsoft.Framework.ConfigurationModel;
3 public IConfiguration Configuration { get; private set; }
5 public Startup()
6 {
7     Configuration = new Configuration()
8         .AddJsonFile("config.json")
9         .AddEnvironmentVariables();
10 }

Line 8 gives me an error: 'Configuration' does not contain a definition for 'AddJsonFile'…

What is wrong?

Best Solution

You need to include the Microsoft.Extensions.Configuration.Json NuGet package if you want to call the .AddJsonFile() method.

See: https://github.com/aspnet/Configuration/tree/dev/src/Microsoft.Framework.ConfigurationModel.Json

For further reading, here's a nice tutorial: ASP.NET vNext Moving Parts: IConfiguration.