Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.6K
Visualizações
appsettings.json vs appsettings.{Environment}.json in .NET Core apps

I am new in .NET Core and as far as I see from my search on the web, appsettings.Development.json is used for development config while developing the app and appsettings.Production.json is used on the published app in production server. Here are the example part that I set on both:

appsettings.Development.json:

"ConnectionStrings": {
  "DefaultConnection": "Server=localhost,21433;Initial Catalog=DemoDbDev;User Id=demouser;Password=******;" 
},

appsettings.Production.json:

"ConnectionStrings": {
  "DefaultConnection": "Server=demo-prod-db,1433;Initial Catalog=DemoDbProd;User Id=demouser;Password=******;" 
},

Here are some question that I need to be clarified:


1) What is the purpose of the appsettings.json? Is it used for default config or for the other settings that are not in the appsettings.Development.json or appsettings.Production.json?

2) Is the environment set on the launchSettings.json in the Properties folder? If so, should we manually update this file before publishing the app to the production server?

3) Is there anything that I should keep in mind regarding to Development and Production environment configs while developing and publishing my app (to IIS Server or Docker container)?

Any help would be really appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

1. About the environment

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0

TLDR; You can get the environment from an environment variable or the launch settings file. The latter is only used for local development.

To determine the runtime environment, ASP.NET Core reads from the following environment variables:

DOTNET_ENVIRONMENT ASPNETCORE_ENVIRONMENT when ConfigureWebHostDefaults is called. The default ASP.NET Core web app templates call ConfigureWebHostDefaults. The ASPNETCORE_ENVIRONMENT value overrides DOTNET_ENVIRONMENT. IHostEnvironment.EnvironmentName can be set to any value, but the following values are provided by the framework:

Development : The launchSettings.json file sets ASPNETCORE_ENVIRONMENT to Development on the local machine

Staging

Production : The default if DOTNET_ENVIRONMENT and ASPNETCORE_ENVIRONMENT have not been set.

2. Settings filled

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

TLDR; You set the defaults and non changing values in the plain json and the overrides in the environment json, as you described.

The default JsonConfigurationProvider loads configuration in the following order:

  1. appsettings.json
  2. appsettings.Environment.json : For example, the appsettings.Production.json and appsettings.Development.json files.

The environment version of the file is loaded based on the IHostingEnvironment.EnvironmentName.

appsettings.Environment.json values override keys in appsettings.json.

3. Keep in mind

Secrets and passwords should not be stored for production environments in the configuration files.

Consider using services like key vault on azure or database encrypted configurations or build server variables that will override the environment specific secrets.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda