Variables for appsettings.SomeEnvironment.json

Good day,

Great product, by the way!

We have been going around in circles trying to find the documentation for this.

I understand that ASP.NET supports multiple environment configs through its launchSettings.json file
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0a

Following that documentation, it would mean we would have

  • Development (my local machine) - appsettings.Development.json
  • Testing - appsettings.Testing.json
  • Production - appsettings.Production.json

How do we make Octopus aware that it is in a particular environment?

In such a scenario, do we create all files in Development and deploy them across all environments?

…or …

Do we make Octopus detect the environment and “generate” a file?

How do I set the ASPNETCORE_ENVIRONMENT environment?

Hi @tinonetic,

First and foremost, welcome to the Octopus forums!

Thanks for reaching out.

Is there any particular reason you’d like to have 3 separate files?

If it works for your use-case, you could have the one appsettings.json file, and then within your project you scope your variables by the environment so the correct variable for each field gets substituted when deploying in that environment.

Documentation: Structured configuration variables - Octopus Deploy

If you do need to have separate files, you could delineate them by using the following syntax.

*\appsettings.#{Octopus.Environment.Name}.json

This results in the following:No files were found that match the substitution target pattern '*\appsettings.Development.json'

Please let me know what you think.

Best,
Jeremy

Hi @jeremy.miller ,

Thank-you for the warm welcome and the quick response.

There’s no real reason why I would use 3 files. It is part of the question. Should I do so or not? What should I do instead?

What is the recommended way of doing it using Octopus?

I had gone through the documentation you posted but I found nothing that I can apply for my scenario.
It seemed like a standard scenario since it’s officially supported, so I guessed that we are failing to understand or find the right documentation on how to implement it properly

If it works for your use-case, you could have the one appsettings.json file, and then within your project you scope your variables by the environment so the correct variable for each field gets substituted when deploying in that environment.

Could you please take me through how I should do this, by example? Step by step?

Thank you!

Hi @tinonetic,

You’re very welcome!

I think it’s probably simplest to just use one appsettings file and scope your variables.

Here is a barebones example:

Step Settings:
First you will need to click Configure Features within your Deploy a Package(or whichever youre using) step and enable “Structured Configuration Variables”. After that, you will need to put in the location and name of the file. Like it says in the tooltip, you can be as specific or as vague as you’d like using wildcards. For my example I just chose any folder, but the name is appsettings.json

Variables within the project:
You will see I have 2 variables, but both variables have 3 separate values. Each value within those variables is scoped to an environment. What this does is it only makes that specific value available to the deployment depending on which environment is currently being targeted by the deployment.

Original base file:
I kept the base file very simple.
image

Resulting deployments:
DEVELOPMENT:


image

TEST:


image

PRODUCTION:


image

Please let me know if that helps or if you have more questions.

Best,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.