I have a .NET Core 1.0.0 console application and two environments. I need to be able to use appSettings.dev.json
and appSettings.test.json
based on
If like me, you're simply trying to have a different configuration file for Release and Development mode, just add a appsettings.Development.json file with CopyToOutputDirectory setting set to true in the file's property window.
Now, to access the file depending on the build configuration, you can use the #if DEBUG preprocessor directive.
Here's an example :
static void Main(string[] args)
{
#if DEBUG
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.Development.json", true, true);
#else
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true);
#endif
var configuration = builder.Build();
// ... use configuration
}