Substitution in config file with variable

Hi! Lets say I have an app.config-file in my project with a bunch of appsettings and a custom section . This project is designed to work on a developers local computer so I need to use real, working values in the config file (ie I cannot use #{MyOctopusVariable}). Now, I want Octopus to replace both appsettings with the current value of a matching octopus variable and the value of “world” with another octopus variable.

I know I can use appsetting-replace-functionality and config transform, but then I would need a lot of config-transform files, which is not satisfactory (have quite a lot of environments).

Lets say I define an dxt transform that will replace “hello” with “#{MyOctopusVariable}”, and then do replace in files wont work because the substitution takes place in the “wrong order”. Does anyone have any suggestion how to solve this. Seems like there should be something out of the box to support this. Why not perform substitution of any #{MyVariable}-occurrence when doing the transformation (of just after the transformation is finished?

some code-like text disappeared from the post. References to “hello” or “world” originated from …mycustomsection key = “hello”, value = “world”…

Hi Emil,

Thanks for getting in touch! Your text disappeared, as this forum uses markdown, but I can see it in your original message.
Octopus uses a number of standard industry recognized conventions such as config transforms.
Our ordering is specific as outlined here:

There are workarounds to changing the order by making use of features such as the pre-deploy PowerShell scripts.
You will see that we do variable substitution on config files after the transformations, but you do not want to work within what is available.
You could use the deploy PowerShell scripts to run your variable substitution after transforms.

Having a look through UserVoice I cannot find any similar requests for a feature addition like this. We have a step template that does the same thing as the substitute variables in files feature but is outside the package step, maybe that is what you are after and will help you find a solution.!/step-template/actiontemplate-file-system-regular-expression-find-and-replace-(updated)

Warm Regards,

There are two types of variable substitionions available: 1. connection string/appsettings, 2. Variable substitution outside connectionstring/appsettings. type 1 is performed after xml transform yes, but type 2 is performed before xml transforms. I just realized that I can work with what is available anyway by doing the “substitute in files” on my config transform file(!)

The process will then be:

  1. replace any octopus variable (outside of appsettings/connectionstrings) in app.mytransform.config
  2. transform app.config using app.mytransform.config

Thanks for the input!

Hi Emil,

I have to admit from your first ticket I thought you had tried this and didn’t like the order. But yes, this is how you can resolve the ordering and run the substitutions first.

Happy to help!