Is launchSettings.json used when running ASP.NET 5 apps from the command line on Mac?

后端 未结 3 629
有刺的猬
有刺的猬 2021-02-18 18:34

I am developing an ASP.NET 5 Web API app using Visual Studio code on Mac. I manually modified my Properties/launchSettings.json file to set environment to Sta

相关标签:
3条回答
  • 2021-02-18 18:57

    LaunchSettings.json is strictly a VS concept. In other cases, you will have to configure environment variables as commands below:

    For standard command line run, use:

    set ASPNET_ENV=Development
    
    dnx web
    

    For powershell, use:

    $env:ASPNET_ENV='Development'
    
    dnx web
    

    Shorter version: dnx web ASPNET_ENV=Development

    0 讨论(0)
  • 2021-02-18 19:14

    Adding to @Chrysalis answer, you could also avoid "messing" with current environment by passing needed variables on command line.

    Inside project.json file, say that you have a web-dev command specific for development environment:

    "commands": {
      "web-dev": "Microsoft.AspNet.Server.Kestrel 
        --ASPNET_ENV Development --Hosting:Environment Development 
        --config hosting.Development.json",
    },
    

    where you can see how both ASPNET_ENV, Hosting:Environment are set, as well as invoking a specific hosting.json configuration.
    NOTE: command is split on several lines just for readability, join again before actually pasting in JSON file.

    0 讨论(0)
  • 2021-02-18 19:19

    On a Mac, using Terminal, type:

    export ASPNETCORE_ENVIRONMENT=Development && dotnet run
    

    Requirements:

    • .NET Core (rc2)
    • .NET command line interface
    0 讨论(0)
提交回复
热议问题