2

I'm creating my CI pipeline in VSO and I have .net core app, I created endpoint which says to me which value was used during publishing, exposing IHostingEnvironment.EnvironmentName through the API, no matter what I do, it's set to Produciton . My app is hosted in Azure.

The steps I did -

I looked into Azure App Service 's application settings, looking for environment. Thinking that might overwrite my variable in Release configuration.

I set ASPNETCORE_ENVIRONMENT variable on variables tab in release configuration, also I set it on specific environment.

setting it on environment: enter image description here enter image description here

setting it on release configuration: enter image description here

And I'm also ruining the command setx with parameter ASPNETCORE_ENVIRONMENT "Test".

setx command

None of the above seems to make any difference, when I query my endpoint I got back I'm running on Production environment. Any help is much appreciated.

vmachacek
  • 530
  • 1
  • 11
  • 27
  • How do you configure .net core project to publish according to the environment? As far as I know it is used for running time. – starian chen-MSFT Jun 22 '17 at 10:14
  • Do you mean set environment when deploy to azure web app? – starian chen-MSFT Jun 23 '17 at 01:41
  • I have appsettings.json, appsettings.Production.json and appsettings.Test.json , based on IHostingEnvironment which is being passed to startup class I load additional configuration specific for an environment. – vmachacek Jun 23 '17 at 06:34
  • What I understood, VSO continuous deployment would set this based on what I passed to the CD pipeline, hence my images atop, however it doesn't seems to take any effect. – vmachacek Jun 23 '17 at 06:37
  • So, you check the value at the runtime after deploying app to azure? If so, then it check the environment of web app server. The variables in build/release are being add to environment temperate of build server for build/release lifecycle. Am I misunderstand you? – starian chen-MSFT Jun 23 '17 at 07:31
  • Yes, I load the configuration at the startup of the app. – vmachacek Jun 23 '17 at 10:26
  • So, you need set environment variable for web app in azure instead in build server. – starian chen-MSFT Jun 23 '17 at 10:58
  • You can configure environment variable in azure portal, check my update. – starian chen-MSFT Jun 26 '17 at 04:41

1 Answers1

6

Regarding variable of build or release, it just affect build server. You need set environment variable for web app in azure instead in build server.

You can configure environment variable in azure portal: Select your App Service> Application Settings> Add ASPNETCORE_ENVIRONMENT key to App Settings and set a value (e.g. Development)

On the other hand, there is a thread about update app settings programing that may benefit you: Change Azure website app settings from code

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • thank you alot for this explanation. Afterwards it's clear that the variables just are for each "stage" and the server in azure is different from the release stage machine. thank you! – Daniel Eisenreich Jun 15 '18 at 06:42
  • 1
    I think setting up variable in release is great but if you are running test script with build then we have to setup on build too. – Ankit Patel Jan 14 '19 at 14:27