[英]how to control the appsettings.json deployment based on environment in .Net Core
I have ASP.Net Core 3.1
application & it has environment based appsettings.json
as我有
ASP.Net Core 3.1
应用程序,它有基于环境的appsettings.json
作为
When the app is published/deployed to any env say UAT , all the appsettings.json gets deployed to the UAT machine.当应用程序发布/部署到任何 env 说UAT时,所有 appsettings.json 都会部署到 UAT 机器。
The requirement is that if the machine/env is UAT, then only below appSettings should be deployed要求是,如果机器/环境是 UAT,那么只应在 appSettings 下面部署
& if the env is Prod then & 如果环境是 Prod 那么
I know the other way is to store/fetch configuration from Environment variables rather appSettings.json but for now that has extra cost for me.我知道另一种方法是从环境变量而不是 appSettings.json 存储/获取配置,但现在这对我来说有额外的成本。
Thanks!谢谢!
This can be controlled by setting the ASPNETCORE_ENVIRONMENT variable on the UAT machine to UAT.这可以通过将 UAT 机器上的 ASPNETCORE_ENVIRONMENT 变量设置为 UAT 来控制。
The defaults that .net core ships with is Development, Staging and Production. .net 内核附带的默认设置是开发、登台和生产。
You can find more information from the MS Docs https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1#set-the-environment您可以从 MS Docs https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1#set-the-environment中找到更多信息
You can set up the "ASPNETCORE_ENVIRONMENT"
variable against your website in IIS.您可以在 IIS 中针对您的网站设置
"ASPNETCORE_ENVIRONMENT"
变量。
Open the "Internet Information Services (IIS) Manager.打开“Internet 信息服务 (IIS) 管理器。
environmentVariables
then you will get the Current env variable.environmentVariables
然后您将获得当前环境变量。 Add a new env variable.name
will be ASPNETCORE_ENVIRONMENT
and value
will be Development[staging/Prod]
. name
将是ASPNETCORE_ENVIRONMENT
并且value
将是Development[staging/Prod]
。 In your case it will be UAT or DEV or Prod
UAT or DEV or Prod
Give a try with the above.试试上面的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.