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.
ok, on Windows set ASPNETCORE_ENVIRONMENT
with this command:
setx ASPNETCORE_ENVIRONMENT Development
so the value stays (notice the 'setx').
Also, look at this answer https://stackoverflow.com/a/43951218/2896495.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With