Deploying a plain ASP.NET Core 2.2 Web App in Azure using Web Deploy is throwing an error

后端 未结 4 923
再見小時候
再見小時候 2021-01-04 13:42

I went to publish an ASP.NET Core web application using Azure through the Publish screen in Visual Studio 2017. I used all of the defaults, though my app uses migra

4条回答
  •  逝去的感伤
    2021-01-04 14:01

    One easy solution would be to put the azure-db connectionstring in the appsettings.json instead of the appsettings.Development.json.

    When running the default generated asp.net core application in VS2017, you can find the launchSettings.Json file in the Properties folder with the profiles which will be run locally. There, under the profiles section you can see that the ASPNETCORE_ENVIRONMENT property is set to Development.

    "WebApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
    

    This means that if you define the local db connectionstring in your appsettings.Development.json it will use its connectionstring when running locally.

    If you don't define the ASPNETCORE_ENVIRONMENT property then the runtime will only use the appsettings.json values (Runtime will set the ASPNETCORE_ENVIRONMENT to Production as default but if you don't have any appsettings.Production.json defined then only the values in appSettings.json will be used).

    So when running the Azure Web App you don't need to specify the ASPNETCORE_ENVIRONMENT at all if you put the azure-db connectionstring in the appsettings.json.

提交回复
热议问题