Appsettings.json不同版本? [英] Appsettings.json Different Versions?
问题描述
我正在启动来自.NET的asp.net core 2.1,想知道如何制作多个AppSetting.json文件?
I am starting asp.net core 2.1 coming from .NET and wondering how do I make multiple AppSetting.json files?
在拥有webconfig之前,您可以拥有webconfig.debug,webconfig.prod等.
Before we had the webconfig that you could have webconfig.debug, webconfig.prod and etc.
与之等效的核心是什么?
What is the core equivalent to that?
推荐答案
默认情况下,ASP.NET Core将尝试加载其他appsettings.<EnvironmentName>.json
文件.使用可用的默认环境名称,这使您可以创建以下文件:
By default ASP.NET Core will attempt to load an additional appsettings.<EnvironmentName>.json
file. Using the default environment names available, this allows you to create the following files:
-
appsettings.json
-加载而与环境名称无关 -
appsettings.Development.json
-仅在环境名称为Development
时加载
-
appsettings.Staging.json
-仅在环境名称为Staging
时加载
-
appsettings.Production.json
-仅在环境名称为Production
时加载
appsettings.json
- loaded regardless of the environment nameappsettings.Development.json
- loaded only when the environment name isDevelopment
appsettings.Staging.json
- loaded only when the environment name isStaging
appsettings.Production.json
- loaded only when the environment name isProduction
开发环境时,通常通过ASPNETCORE_ENVIRONMENT
环境变量或launchSettings.json
控制环境的名称(
The name of the environment is usually controlled via the ASPNETCORE_ENVIRONMENT
environment variable or via launchSettings.json
when developing (checkout the docs).
Take a look at the documentation for configuration for more info regarding this topic.
这篇关于Appsettings.json不同版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!