0
votes

I have Asp.Net core web api project. I want to add some configurations for development environment during debugging with iis express so, I added new file "appsettings.Development.json" under "appsettings.json" one. When I put the connection string in this file I had exception with connecting the database. If I remove the connection string from this file and put it in "appsettings.json" It works fine (the same connection string).

By default we have two settings files for production and staging but not for development. Is this the correct way to add those configurations during development?. Or should I depend on "appsettings.json" only during development?.

Note: when publish the project and put it under IIS server every thing is fine with "appsettings.Development.json" also.

1

1 Answers

1
votes

if you have environment specific appsettings file, they are loaded based on value of "ASPNETCORE_ENVIRONMENT" environment variable.

This value may get overwritten by the value in .vscode/launchsettings.json The JSON configuration loaded are from appsettings.{environment}.json

It depends on you on how you want to organize the configuration files. If you want seprate configuration file for every environment you can keep separate appsettings.{environment}.json file. Or else you can keep single file and change these values during CI/CD pipeline.

Reference: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2