Rename.config files outside of web.config files

I’m trying to utilize Configuration transforms to rename the .config files but its not working. so far I have created environment variables and created additional transform
#{Environment}.GTS.Config => GTS.Config
#{Environment}.RDC.Config => RDC.Config
#{Environment}.STG.Config => STG.Config
#{Environment}.SunSystems.Config => SunSystems.Config
#{Environment}.UGM.Config => UGM.Config
however when I check the file location the files are not being replaced and I receive this message from octopus when I look at the verbose log
The expected namespace http://schemas.microsoft.com/XML-Document-Transform was not found in the transform file
However I don’t need it to replace any variables within the .config file just rename it from #{Environment}.UGM.Config to UGM.Config

Hi James,

Thanks for reaching out! The Configuration Transforms feature doesn’t do file renaming. What it does is use a file with config transforms syntax (left side of the =>) and applies it to another config file (right side of =>).

If you need to rename files that way, you’ll need to add a Powershell script to do so.

Thanks,
Dalmiro

Thanks Dalmiro. Does that mean that if I created environmental Variables octopus can’t replace a .config based on the environment. e.g #{Environment}.GTS.Config => GTS.Config (Meaning it will find the dev.GTS.config file and rename it to GTS.config and replace the old GTS.config if any existed?

Does octopus have that type of functionality?

Best Regards,

James Noel
Assurant Solutions | IT Solutions - International
Application Engineer | Miami -305-253.2244.32625 | james.noel@assurant.commailto:james.noel@assurant.com

Hi James,

That renaming functionality doesn’t exist in Octopus out of the box. What does exist is the usage of Configuration Transforms so you can tell Octopus to transform GTS.config using #{Environment}.GTS.Config.

What you want to do now is totally possible using Powershell though. You can even add that script as a Pre-Deploy Script so it gets executed in the same step as the package deployment.

Thanks,
Dalmiro

Is it possible to give me an example of that script so I can add that script as a Pre-Deploy Scripthttps://urldefense.proofpoint.com/v2/url?u=http-3A__docs.octopusdeploy.com_display_OD_Custom-2Bscripts-23Customscripts-2DScriptsinpackagesteps&d=CwMFaQ&c=59WElTcIEwbBjXQe6gMr9RyqhrzJYRWAhv5h0b8rPQw&r=pkyo-NRcatYVgGsdpVIttYyNgvvRFanIREHnSagj0QU&m=vsjuhBNiXZvqYPtrx2g1PqT8C0T1Ohw35tT2UXMB82s&s=qsIKrsrpwo02jMrfkqu4McItlbYtkFtCmodoqYaa5YI&e= and test in my lab?

Best Regards,

James Noel
Assurant Solutions | IT Solutions - International
Application Engineer | Miami -305-253.2244.32625 | james.noel@assurant.commailto:james.noel@assurant.com

I can give you a hand with that yeah. I’m gonna need a couple of things though:

  • Use the Nuget Package explorer to open your nuget package and then send me a screenshot where I can see the names of all the .config files and where they are located inside the package.

  • Send me a screenshot of your project variables where I can see how you configured this #{Environment} variable.

Thanks,
Dalmiro

Here you go
First this is the Nuget package and all of the config files are located in the config folder

[cid:image001.png@01D20383.DA0140C0]

Secondly here are the Project variables I created

[cid:image002.jpg@01D20383.DA0140C0]

Best Regards,

James Noel
Assurant Solutions | IT Solutions - International
Application Engineer | Miami -305-253.2244.32625 | james.noel@assurant.commailto:james.noel@assurant.com

Dalmiro,

Any luck with the screenshots I sent you?

Best Regards,

James Noel
Assurant Solutions | IT Solutions - International
Application Engineer | Miami -305-253.2244.32625 | james.noel@assurant.commailto:james.noel@assurant.com

Hi James,

I got them, but I still haven’t had the time to work on that script. Since you are here can I ask you one thing?

Lets say you deploy to the environment AS_Felita China and the variable Environment resolves to test, what do you expect to happen to your config files RE renaming, deletion, etc? I wnt to better understand what the script needs to do.

Thanks,
Dalmiro

I assumed that the environment variables I created are used for the naming of the config file and it doesn’t matter where they are deployed if its any Dev environment it would look for Test.***.Config and replace it to ***.config. same for Model and Prod environment it would look for modl.***.config and prod.***.config is that assumption wrong?

Best Regards,

James Noel
Assurant Solutions | IT Solutions - International
Application Engineer | Miami -305-253.2244.32625 | james.noel@assurant.commailto:james.noel@assurant.com

Hi James,

Unfortunately that assumption is wrong, yeah. Those Project variables scoped to environments (like “environment” in your screenshot) are only variables that you can later reference in your deployment process to do things. Octopus doesn’t use these variables to rename any files at all. If you found that somewhere in our documentation, please let me know so I can fix/rephrase it.

In your case what you need is a custom script that adds this functionality for you making use of these variables.

Do you by any chance know Fahim.Hack from Assurant? His team seems to be quite advanced in the usage of Octopus (we’ve been exchanging emails with him for quite a while now) and they might be able to give you a hand with this custom script.

Thanks,
Dalmiro

Ill reach out to him and let you know.

Best Regards,

James Noel
Assurant Solutions | IT Solutions - International
Application Engineer | Miami -305-253.2244.32625 | james.noel@assurant.commailto:james.noel@assurant.com

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.