[英]How to set appsettings.json automatically for deployment in ASP.NET Core?
I look at several topics eg Automatically set appsettings.json for dev and release environments in asp.net core?我看了几个主题,例如自动设置 appsettings.json 用于 asp.net 核心中的开发和发布环境? and see that I can create appsettings.{Environment}.json in .NET Core apps and set the environment in
launchSettings.json
.并看到我可以在 .NET 核心应用程序中创建 appsettings.{Environment}.json 并在
launchSettings.json
中设置环境。
However, I am wondering what should I do to set this environment properly while publishing my app to IIS or Docker container.但是,我想知道在将我的应用程序发布到 IIS 或 Docker 容器时应该如何正确设置此环境。 Before each publishing, should I change the
environmentVariables
parameter to Prod and then update it to Development after publish?在每次发布之前,我是否应该将
environmentVariables
参数更改为 Prod,然后在发布后将其更新为 Development? I do not think so, but I could not find a suitable page explaining this.我不这么认为,但我找不到合适的页面来解释这一点。 Could you please clarify me about this issue?
你能澄清一下这个问题吗?
First of all as docs state: launchSettings.json
is only used on the local development machine.首先作为文档 state:
launchSettings.json
仅在本地开发机器上使用。
As for using configuration file - by default next files are used:至于使用配置文件 - 默认情况下使用下一个文件:
appsettings.json
using the JSON configuration provider.appsettings.json
使用 JSON 配置提供程序。appsettings.Environment.json
using the JSON configuration provider.appsettings.Environment.json
使用 JSON 配置提供程序。 For example,appsettings.Production.json
andappsettings.Development.json
.例如,
appsettings.Production.json
和appsettings.Development.json
。
The environment for ASP.NET Core app determined next way: ASP.NET 核心应用程序的环境通过以下方式确定:
To determine the runtime environment, ASP.NET Core reads from the following environment variables:
为了确定运行时环境,ASP.NET Core 从以下环境变量中读取:
DOTNET_ENVIRONMENT
ASPNETCORE_ENVIRONMENT
whenConfigureWebHostDefaults
is called.调用
ConfigureWebHostDefaults
时的ASPNETCORE_ENVIRONMENT
。 The default ASP.NET Core web app templates callConfigureWebHostDefaults
.默认的 ASP.NET Core web 应用程序模板调用
ConfigureWebHostDefaults
。 TheASPNETCORE_ENVIRONMENT
value overridesDOTNET_ENVIRONMENT
.ASPNETCORE_ENVIRONMENT
值覆盖DOTNET_ENVIRONMENT
。
So the usual approach is to set ASPNETCORE_ENVIRONMENT
environment variable to needed value on target host (machine, docker container, etc...)所以通常的方法是在目标主机(机器、docker 容器等)
ASPNETCORE_ENVIRONMENT
环境变量设置为所需的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.