JSON variable substitution in appsettings.json file is not working in Azure DevOps Releases

Viewed 8675

I am using Visual Studio 2019 to create a Restful Web API in C# using ASP.NET Core 3.1. I am trying to replace a value (AppSettings.ReleasePipeline) in my appsettings.json file in the release pipeline to different values for each stage, but it is not getting set on any stage and is just using the value in the appsettings.json file that is already there.

Here is my appsetttings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "CodeCampDatabaseConnectionString": "Data Source=.;Initial Catalog=PSCodeCamp;User Id=sa;Password=Dallas!@#;Connect Timeout=30;"
  },
  "AppSettings": {
    "ReleasePipeline" : "Environment from AppSettings"
  }
}

The variables in my release pipeline, look like this:

Image of my Release Pipeline

If someone could assist, I would really appreciate it.

1 Answers

This feature substitutes values in the JSON configuration files. It overrides the values in the specified JSON configuration files (for example, appsettings.json) with the values matching names of release pipeline and stage variables.

To substitute variables in specific JSON files, provide newline-separated list of JSON files. File names must be specified relative to the root folder.

If you want to substitute values in appsettings.json, enter the relative path from the root folder; for example content/website/appsettings.json. Alternatively, use wildcard patterns to search for specific JSON files.

For more details, you could refer to this article.

Related