如何设置 appsettings.json 自动部署到 ASP.NET Core?
How to set appsettings.json automatically for deployment in ASP.NET Core?
我看了几个主题,例如 并看到我可以在 .NET Core 应用程序中创建 appsettings.{Environment}.json 并在 launchSettings.json
.
中设置环境
但是,我想知道在将我的应用程序发布到 IIS 或 Docker 容器时,我应该如何正确设置此环境。每次发布前,是不是要把environmentVariables
参数改成Prod,发布后再更新成Development?我不这么认为,但我找不到合适的页面来解释这一点。你能解释一下这个问题吗?
首先,如文档所述:launchSettings.json
在本地开发机器上是 only used。
至于使用配置文件 - by default 使用下一个文件:
appsettings.json
using the JSON configuration provider.
appsettings.Environment.json
using the JSON configuration provider. For example, appsettings.Production.json
and appsettings.Development.json
.
ASP.NET核心应用的环境确定next方式:
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
.
所以通常的方法是将 ASPNETCORE_ENVIRONMENT
环境变量设置为目标主机(机器,docker 容器等)上所需的值
我看了几个主题,例如launchSettings.json
.
但是,我想知道在将我的应用程序发布到 IIS 或 Docker 容器时,我应该如何正确设置此环境。每次发布前,是不是要把environmentVariables
参数改成Prod,发布后再更新成Development?我不这么认为,但我找不到合适的页面来解释这一点。你能解释一下这个问题吗?
首先,如文档所述:launchSettings.json
在本地开发机器上是 only used。
至于使用配置文件 - by default 使用下一个文件:
appsettings.json
using the JSON configuration provider.appsettings.Environment.json
using the JSON configuration provider. For example,appsettings.Production.json
andappsettings.Development.json
.
ASP.NET核心应用的环境确定next方式:
To determine the runtime environment, ASP.NET Core reads from the following environment variables:
DOTNET_ENVIRONMENT
ASPNETCORE_ENVIRONMENT
whenConfigureWebHostDefaults
is called. The default ASP.NET Core web app templates callConfigureWebHostDefaults
. TheASPNETCORE_ENVIRONMENT
value overridesDOTNET_ENVIRONMENT
.
所以通常的方法是将 ASPNETCORE_ENVIRONMENT
环境变量设置为目标主机(机器,docker 容器等)上所需的值