Prevent the config transforms being written to disk

I like the configuration transform capability in Octopus Deploy and make quite heavy use of it, however it does annoy me that the transforms for all environments are always written to the app directory on the target machine.

e.g. I have a windows service with 3 environment transforms:

  • Company.Service.exe
  • Company.Service.exe.config
  • Company.Service.exe.Development.config
  • Company.Service.exe.Test.config
  • Company.Service.exe.Production.config

It would be nice if on a machine, I only had the app config post transform e.g.

  • Company.Service.exe
  • Company.Service.exe.config (after Company.Service.exe.{Environment}.config has been applied}

Is there a way to prevent that happening?

HI Trevor,

Thanks for reaching out. The only way to do this is by adding a custom script that deletes the files you want.

We try to be safe-by-default and assume that if the user puts the file into the package, its because it wants it deployed. And if the user wants a certain package to be deleted, they can do so programatically using a Post-deploy script like this:

#List of files with .config extension to keep
$filesToKeep = ("web.config","App.config")

#deleting all .config files that are not in $FilesToKeep
Remove-Item *.config -Recurse -Exclude ($filesToKeep) -Verbose

please try it on a test environment first. I typed it without testing :slight_smile:


That makes sense, OK thanks I’ll have a play with that script!

One of my teammates pointed out to me that we have a step template submitted by the community that does something similar in our library:

The community template step worked a treat, thanks!