Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jay 425 posts 652 karma points
    Mar 03, 2022 @ 07:40
    Jay
    0

    AppSettings.json transform

    Hi All,

    I've been trying out the Umbraco V9 just to get a feel on how things works and I've been checking the config transform bit which I don't quite understand

    Link as below https://our.umbraco.com/documentation/reference/V9-Config/

    So for example if I have a test Release environment which I want to push and I need that to use the AppSettings.Release.json config to transform.

    I've tried publishing using a Publish Profile and had selected the Release Configuration in VS enter image description here

    But when I publish it sort of pushes both AppSettings.Release.json and AppSettings.json to the Azure Web App.

    In the documentation link above. It says it detect which AppSettings to use based on which environment that you set as per the screen shot below. But is this like a settings that I need to set within Azure Web App to say that it's a release environment? I'm confused enter image description here

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Mar 03, 2022 @ 08:07
    Kevin Jump
    100

    Hi

    Yeah i found this confusing when i first looked at it too.

    The config isn't transformed at build time but rather run time, and depends on the runtime state that the site is in.

    This is actually determined by the value of the ASPNETCORE_ENVIRONMENT environmental variable. the file merged into the appsettings.json takes the form appsettings.{{environment}}.json. eg. appsettings.development.json.

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

    when you are working locally, there is usually a properties/launchsettings.json file that sets this up so you will see something like :

      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        },
        "Umbraco.Web.UI": {
          "commandName": "Project",
          "dotnetRunMessages": true,
          "launchBrowser": true,
          "applicationUrl": "https://localhost:44328;http://localhost:17621",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }      
        }
    

    When running on something like azure or a local iis server this needs to be set to 'production' or 'release' or what ever it is you want to use for your appsettings file.

    For example for azure web app there you can set it in the portal : this blog post has a good summary of the options https://thecodeblogger.com/2021/04/12/multiple-ways-to-set-hosting-environment-in-net-applications/

  • Jay 425 posts 652 karma points
    Mar 03, 2022 @ 08:28
    Jay
    0

    Omg Kevin you're a saviour.

    The environment variable ASPNETCORE_ENVIRONMENT is what I've been missing. It's not mentioned in the Umbraco Docs too (which I think they should).

    Everything loads accordingly now. Super happy

Please Sign in or register to post replies

Write your reply to:

Draft