In my .net core 1.1 app I have different configurations, which are written in appsettings.json files: appsettings.dev.json, appsettings.production.json, appsettings.test.json.
For each configuration I have different environments in AWS Beanstalk. Right now I'm deploying to Beanstalk by uploading zip file, which contains compiled .net core code and AWS manifest. By default .net core is using production configuration. I was trying to override it several ways:
- dotnet publish --configuration Test
- added environment variable ASPNETCORE_ENVIRONMENT Test in Beanstalk software configuration
- added web.config in which specify ASPNETCORE_ENVIRONMENT environment variable
It doesn't work. The only way which I found work for me was .UseEnvironment("Test"):
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseSetting("detailedErrors", "true")
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
// TODO: fix me! It's used for AWS deployment
.UseEnvironment("Test")
.Build();
host.Run();
}
It means that before deployment I need to change hardcoded configuration and it isn't a nice solution.
Does anyone knows how to deal with different configurations in AWS Beanstalk?