净核心环境未切换

问题描述 投票:0回答:2

我无法在开发和暂存之间切换环境。

无论环境变量是什么,它都会保持在分段状态。

这是我的launchsettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost/WebService",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:51658/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Staging"
      }
    },
    "WebService": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:51659/"
    }
  }
}

无论我使用什么发布配置文件,环境仍然是'Staging'

至于appsettings.X.json去,我有3。

appsettings.json
appsettings.Development.json
appsettings.Staging.json
c# asp.net-core .net-core
2个回答
1
投票

您必须通过设置Windows环境变量来设置环境。将使用此环境加载正确的appsettings.json文件。

这可以通过执行命令行来完成

set ASPNETCORE_ENVIRONMENT=Development

This website展示了如何为不同的操作系统设置环境。


0
投票

我认为这取决于您使用什么来维护应用程序Docker,IIS或其他东西。

文件说:

在IIS应用程序池

要为在隔离的应用程序池中运行的各个应用程序设置环境变量(在IIS 10.0+上受支持),请参阅环境变量主题的AppCmd.exe命令部分。

您可能需要在隔离环境中运行应用程序,并且为此需要设置该变量。

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments

© www.soinside.com 2019 - 2024. All rights reserved.