如何生成appsettings.< EnvironmentName> .json文件? [英] How to generate the appsettings.<EnvironmentName>.json file?
问题描述
我有一个asp.net core 2 Web API,它将在以下环境中部署:
I have an asp.net core 2 web api which will be deployed across the following environments:
INT,QA,STAGE,PRODUCTION环境.
INT, QA, STAGE, PRODUCTION environments.
基于上述,我需要为每个环境提供appsettings.<EnvironmentName>.json
文件.从链接: https://docs.microsoft .com/en-us/aspnet/core/fundamentals/environments?view = aspnetcore-2.1 ,我看到
Based on the above, I need to have appsettings.<EnvironmentName>.json
file for each environment. From the link : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.1 , I see that
如果是本地开发环境,则将称为ASPNETCORE_ENVIRONMENT的环境变量设置为开发".如果部署中未设置ASPNETCORE_ENVIRONMENT,则默认值为生产
In case of local development environment, the Environment Variable called ASPNETCORE_ENVIRONMENT is set to Development. In case of the deployment where ASPNETCORE_ENVIRONMENT is not set, the default is Production
我想知道在为INT,QA和STAGE环境准备appsettings.<EnvironmentName>.json
文件时需要采取哪些步骤?我是否需要为每个环境Web服务器显式设置环境?
I would like to know what are the steps required to take care while preparing the appsettings.<EnvironmentName>.json
file for INT, QA and STAGE environment. Do I need to set the environment explicitly for each environment web server:
set ASPNETCORE_ENVIRONMENT =开发.
set ASPNETCORE_ENVIRONMENT=Development.
有人可以通过提供指导来帮助我吗?
Can anyone help me to by providing their guidance?
推荐答案
我可能遗漏了一些东西,但这似乎很简单.要创建特定于环境的设置文件,您只需在项目中创建它们,即在项目的根目录中创建一个名为appsettings.Foo.json
的新文件. Visual Studio会将其作为父项自动放置在appsettings.json
下,位于解决方案资源管理器中.
I might be missing something, but this seems pretty straight-forward. To create the environment-specific setting files, you literally just create them in your project, i.e. create a new file called appsettings.Foo.json
in the root of your project. Visual Studio will automatically put it under appsettings.json
as a parent in the Solution Explorer.
是的,在服务器上,您需要将要在其下运行的环境设置为ASPNETCORE_ENVIRONMENT
.如果应该使用appsettings.QA.json
,则将其设置为QA
.这就是全部.
On the server, yes, you'd need to set the environment you want to run under to ASPNETCORE_ENVIRONMENT
. If it's supposed to use appsettings.QA.json
, then set it to QA
. That's all there is to it.
这篇关于如何生成appsettings.< EnvironmentName> .json文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!