I want to use the IHostingEnvironment
and ConfigurationBuilder
in my functional test project, so that depending on the environment the functional tests
This is possible, according to the ASP.NET Core documentation (http://docs.asp.net/en/latest/fundamentals/configuration.html) you can build this inside the Startup method and add the Environment variable appSettings. When specifing the optional flag you can use the appSettings.Production.json for production environment and appSettings.json for development when there is no appSettings.Development.json available. The appsettings.{env.EnvironmentName}.json is only used when the file is present and the fallback is the default appsettings.json
public Startup(IHostingEnvironment env)
{
// Set up configuration providers.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}