2

I have currently 3 appsetting.jsons

appsettings.Development
appsettings.Production
appsettings.Qa

I have my visual studio to built with Development, but now I want to publish my code to my QA server.

Howe can set up my code to automatically publish with the right "ASPNETCORE_ENVIRONMENT" value so that the QA IIS knows to use the "appsettings.Qa" config.

I don't want to manually setup the environment variables on the server as if it changes, I can see people will forget to reset it.

chobo2
  • 83,322
  • 195
  • 530
  • 832
  • Will you mind setting `ASPNETCORE_ENVIRONMENT` by `web.config`. refer [Setting environment variables](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1#setting-environment-variables) – Edward Aug 13 '18 at 09:53
  • @Edward - I am just a bit confused with this way, I don't see a web.config in my .net core project. So do I create one and do I have to create a web.qa.config, web.release.config and such? – chobo2 Aug 13 '18 at 16:15
  • Right-click the project to add `web.config`, and modify the content like the link in my previous comment. There is no need to create different web.config for different environment, but, you will need to change the `ASPNETCORE_ENVIRONMENT` value in web.config when you want to switch different environment. I think it is convenience than system environment variable. – Edward Aug 13 '18 at 16:23
  • So will this override the web.config that gets generated on publish? – chobo2 Aug 13 '18 at 23:43
  • Yes, it will override on publish. – Edward Aug 14 '18 at 00:46
  • Ok, I will try this. Just wondering if maybe I should make some webconfig tranforms or if there is a better way as I don't want to manually have to change the environment before build, as I know I am going forget. – chobo2 Aug 14 '18 at 20:06
  • While pubblishing, web.config will be published to output folder. You just need to change the published web.config based on your required environment when you need to change after publishing. – Edward Aug 15 '18 at 00:46
  • are you talking of hooking a web transform to a different release type? – chobo2 Aug 15 '18 at 16:22
  • @Edward - Also when I copy and paste that code into a webconfig my localhost does not work. I hit F5 in VS and I get an error in the nature of "unable to start process C:\Program Files\dotnet\dotnet.exe" – chobo2 Aug 15 '18 at 23:30
  • @Edward - I re-read your last comment, it seems like your saying that you can't make something that will automatically change the "value" in the web.config based on a flag or something. I was hoping I could make different publish packages and when I choose one, a transform will happen and the correct "flag" will be put in the web.config. So is there anyway to do this? – chobo2 Aug 15 '18 at 23:32
  • Yes, I could not automatically change the value. Out of my mind. Hope others will proivde the solution. – Edward Aug 16 '18 at 08:09
  • You can see this [ [awnser] ](https://stackoverflow.com/a/37859691/1343366) I hope this could help you :) – JBA Jul 31 '19 at 07:33
  • You can see this [answer](http://stackoverflow.com/a/37859691/1343366) I hope this could help you – JBA Jul 31 '19 at 07:35

0 Answers0