What is the best way to comment out connection strings during a deployment

Hello,
Octopus newbie here. I need a way to comment out connection strings during the deployment? What is the best way of doing this?

thanks,

Jesus

Hi Jesus,

Thanks for reaching out. Instead of commenting it, I’d recommend you remove it using the “Configuration Transforms” technique shown on this doc:

Here’s more info about Config transformation syntax, look for Transform="Remove"

https://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

Hope that helps,

Dalmiro

Thank you for your quick reply.

Let say I only want to remove the connection string to only a couple of servers belonging to the same project/environment. Do I just create a custom script that will identify the servers then run the transformations?

Hi,

The most common and recommended approach for this scenario where you need different connection strings depending on the environment you are deploying to goes like this:

  • You have a base web.config which doesn’t have any connection strings on it. By itself it wont work regardless if you are deploying to Prod, Stage or your Dev box.

  • You have 1 config transform file per environment where you’ll be deploying your app. Lets say you’ll be deploying to Dev, Stage and Prod. Each config file will be named Web.[env name].config, leaving you with the following files:

    • web.dev.config
    • web.stage.config
    • web.prod.config
  • Each config file will use Microsoft’s configuration transformation syntax to insert the configs needed by your (currently empty) web.config to work in the selected environment. This gives you a lot more flexibility, as its easier to add configs to an empty web.config, rather than cherry picking the ones you want to remove depending on the environment.

  • In Octopus, you’ll create a variable called TransformFile per environment which will have the config file name as its value, an which will be scoped its correspondent environment. See attached image.

  • In your NuGet deploy step, on the additional transform field you’ll put #{Transformfile} => web.config(see attached image). This way Octopus will use the correct config transform file depending on the environment you are deploying to.

Hope this rant makes sense and helps you
Dalmiro