【问题标题】:How to reference environment variables in launchsettings.json on linux如何在 Linux 上的 launchsettings.json 中引用环境变量
【发布时间】:2021-10-13 10:55:35
【问题描述】:

我在我的项目中配置了一个开发证书。证书路径在我的HOME 目录中。

当我配置环境变量ASPNETCORE_Kestrel__Certificates__Default__Path时,没有

$HOME/.aspnet/https/localhost.pfx
$(env:HOME)/.aspnet/https/localhost.pfx
${HOME}/.aspnet/https/localhost.pfx

有效。现在我设置成/home/nemo/.aspnet/https/localhost.pfx就可以正常运行了。

我参考this answer,但它似乎只适用于PowerShell,而我使用zsh。

【问题讨论】:

    标签: c# linux asp.net-core


    【解决方案1】:

    需要在服务器上设置环境变量:

    **LINUX**
    
    export ASPNETCORE_ENVIRONMENT=Staging
    
    **POWERSHELL**
    
    $Env:ASPNETCORE_ENVIRONMENT="Staging"
    
    **WINDOWS**
    
    set ASPNETCORE_ENVIRONMENT=Staging
    

    参考文件:

    Use multiple environments in ASP.NET Core

    【讨论】:

    • 好像是整个OS的配置,但我只想为这个项目配置。
    • 要不要在launchSettings.json中单独配置这个项目的环境?可以参考本帖的做法,可能对你有帮助:stackoverflow.com/questions/52883707/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2012-05-14
    • 1970-01-01
    相关资源
    最近更新 更多