I use this code to load settings depending on Environment in my xUnit test project:
public class TestSettings
{
public string AzureConnectionString { get; }
public TestSettings(ITestOutputHelper output)
{
string envVariable = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
output.WriteLine($"env: '{envVariable}'");
IConfigurationRoot config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{envVariable}.json", optional: true)
.Build();
AzureConnectionString = config.GetConnectionString("AzureStorage");
}
}
But whatever I do I get envVariable
empty. Where can I set ASPNETCORE_ENVIRONMENT
for test project (VS2017)?
To ASP.NET Core Tooling Team
Please make test project settings work for environment. Thank you.