locked
Switching environment when publishing asp.net core web api RRS feed

  • Question

  • User2070555482 posted

    Hi I'am want to ask on how to switch between environment when publishing an app?

    Currently I have my web api that in my local machine and the default environment is "Development" in appsettings.json. And when i publish the app then it override the appsettings,json in server. I know that we can have different appsettings.json for production or development. My question is how can i tell the app that this is the appsettings that you will use when you in the server and that's when you are in the development machine 

    Monday, October 28, 2019 3:52 AM

Answers

All replies

  • User475983607 posted

    TinVin727

    Hi I'am want to ask on how to switch between environment when publishing an app?

    Currently I have my web api that in my local machine and the default environment is "Development" in appsettings.json. And when i publish the app then it override the appsettings,json in server. I know that we can have different appsettings.json for production or development. My question is how can i tell the app that this is the appsettings that you will use when you in the server and that's when you are in the development machine 

    Just read the documentation, it has everything you need.  

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.0

    I prefer to set the ASPNETCORE_ENVIRONMENT Windows Environment variable in each server.  You do this once.  Name the configuration file to match the environment; appsettings.staging.json.

    Monday, October 28, 2019 12:10 PM
  • User1634355159 posted

    Hi TinVin727,

    ASP.NET Core references a particular environment variable, ASPNETCORE_ENVIRONMENT to describe the environment the application is currently running in. This variable can be set to any value you like, but three values are used by convention: Development, Staging, and Production.The following link shows the configuration method:

    https://aspnetcore.readthedocs.io/en/stable/fundamentals/environments.html#determining-the-environment-at-runtime

    Best Regards,

    Lewis

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 29, 2019 7:25 AM