"How to add new lines or new code in Configuration files" before deployment

Hi,

We have a requirement that “we need to add some new lines of code or some piece of changes in configuration files which will be not in our Nuget packages”, so kindly let me know ASAP how to do it?

Thanks,
Murali Prasad

Hi Murali,

If you need to do something more dynamic and web config transformations doesn’t get you there then the best approach is to use a custom PowerShell script to add the nodes, usually a deploy.ps1 script. Something like this would do it if you wanted to add an appSettings entry.

$filePath = [path to my web.config file]

# load the XML from the web.config
$xml = New-Object XML
$xml = [xml](Get-Content $filePath)

$setting = $xml.CreateElement('add')
$setting.SetAttribute('key','Name')    

$xml.configuration.appSettings.AppendChild($setting)

$xml.Save($filePath)

Hope that helps!

Daniel

Hi Daniel,

Thanks for your reply.

Actually we are looking that can we do it directly from Octopus rather than going to a Powershell.
So, kindly specify the process how to do it.

Thanks,
Murali Prasad

Hi Daniel,

Any Update on this?
This is a very urgent requirement for us…

Thanks,
Murali Prasad

Hi Murali,

As Daniel explained, if you cannot find your solution using our Configuration Files inbuilt solutions


Then the PowerShell provided is the only way to get what you need.

I am closing the second ticket, as we do not need two of the same tickets open.
Vanessa