mardi 12 décembre 2017

How to set ASPNETCORE_ENVIRONMENT when testing .NET Core 2.0 class library with xUnit in VS2017

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)?

Aucun commentaire:

Enregistrer un commentaire