Search code examples
asp.net-coreasp.net-core-mvcazure-service-fabric

Hosting Environment Asp.net Core on Service Fabric local cluster


I'm having hard time setting the Hosting Environment to "Development" for my Asp.net Core Stateless Service hosted in a local Service Fabric Cluster.

I set the variable ASPNETCORE_ENVIRONMENT to Development in my machine, and in all the config in the Asp.net Core project

enter image description here

But during debug

env.IsDevelopment()

ia always false.

How can I solve this?


Solution

  • I was able to get Development mode enabled by setting the ASPNETCORE_ENVIRONMENT variable to Development in System environment variables. (Control Panel, System, Advanced System Settings, Advanced tab, Environment Variables.)

    Note that as soon as I ran the app, then, the following line in Startup.cs threw an exception:

    builder.AddUserSecrets();
    

    This is because the user secrets are contained in project.json, which is not, by default, included in the deployment. You can either remove the offending line above, or, while developing, include project.json in the list of includes under publishOptions in project.json itself:

    "publishOptions": {
      "include": [
        "wwwroot",
        "**/*.cshtml",
        "appsettings.json",
        "web.config",
        "project.json"
      ]
    },