Build web.config before deploy

I am currently migrating my deployment to use Octopus Deploy instead. I have gotten far, however I was wondering how to build the Web.config files. Prior to migrating we had a PowerShell script that we ran on the drop folders from TFS build, which then deployed the application as well as building the config files using the MSBuild installed on the computer running containing the drop folder.

However with Octopus Deploy I had to install MSbuild tools on the tentacle and then run a similar powershell script, that is run on the tentacle. This seems to me like a problem, since I don’t want to install MSBuild on each environment I’m deploying to as well as the fact that I don’t want to build anything on production environments. So how can I achieve the same functionality as before?

Meaning I want to build the config files prior to deploying them. I didn’t get this to work by adding parameters in the build definition.

Thanks!
Mike

Hi Michael,

Thanks for getting in touch.

Managing configuration files is one of Octopus Deploy’s strengths. I suggest you read the Configuration files page in our documentation.

You certainly won’t need to deploy MSBuild to your Tentacles. Octopus can transform your configuration files on the Octopus server before pushing them to each Tentacle. The two main methods of managing your config files are variable substitution and configuration transforms; I’ll let you read the documentation rather than repeating it here.

I hope this helps. If we can be of any further assistance, you know where to find us.

Regards,
Michael R

Hi Michael,

Thank you for your email. However, in our solution we have a different structurenin how we handle config files. We have the following structure:

Web.UI project > [Configuration] > Environment > config files
And then a file in Web.UI project > [MSBuild] > BuildSpecificConfigTransforms.xml where we specify transform rules.

How would we go about when having this structure? The web.config is never building unless if we run it manually.

Is it possible or would we need to change our structure?

Thanks!
Mike

Skickat från min iPhone

Mike,

I don’t completely understand your current process, but hopefully I can offer some guidance.

We always recommend making configuration management part of your deployment, rather than your build. The good news is, I think you have everything you need to make this happen.

If I understand correctly, you have environment-specific configuration transforms that you run over your web.config for each environment. Octopus Deploy can execute your transforms. The only catch is, they will need to be in the same directory as your web.config. It can automatically apply transforms in the format web.{{Environment}}.config, or you can specify explicitly which transforms to apply (see the Additional Configuration Transforms section in this document).

The other key feature of Octopus that I would encourage you to use is variables. Where you were probably previously managing environmental variables in your source (in the config transforms), these are again a deployment concern, and are better managed by Octopus. You can scope variables per environment (meaning they can have different values for each environment). And by using the Substitute variables in files feature, you can replace variables in config or transform files. Using variable-substitution on a transform file, and then running the transform, provides a very powerful combination.

In summary, Octopus can run your existing transforms for you. And it can manage your environment-specific variables. If you have any specific questions, we’re more than happy to help.

I hope this helps,
Michael R

Hi Michael,

I’ve tried to clairfy the problem in a stackoverflow question: http://stackoverflow.com/questions/33239207/specific-web-config-location-octopus-deploy

I’m not getting it to work, I have loads of config files, and my current deployment script transforms all these config files, moves them to http://Web.UI/[Configuration]/ folder and then moves transformed Web.Config to http://Web.UI/Web.config. So to start off my Web.config file only exists in the different environments, where Main is a scaffold for all environments.

Hope it clarifies my issue. Do you know if there is any guide on how to do this? Since it’s so many environments in consideration, it would be awful to put them all in the same folder…

Best regards,
Mike
13 oktober 2015 01:25:53 +02:00, skrev Michael Richardson tender2+dc3cba3771@tenderapp.com:

Can I ask why you duplicate the configuration files for each environment?

The usual approach is to have only the one copy of the configuration files, and then have transforms for each environment, or even just one transform that you use variable-substitution on to insert the environment-specific variables before running the transform.

Sorry for the confusion. All configs in main are the real .config files. The other environment folders only contain specific transforms for each config file per environment. So there are no duplicates.

However, I figured it is just easier to just restructure our config files and instead of structuring a folder per environment I now use a folder per config files, then rename config files like this: Main: Web.config, Dev: Web.Dev.config. And that works superb with octopus. I didn’t set up the original structure, so I’m not sure why we didn’t do this to begin with.

Thank you Michael for all the assistance though.

Best regards,
Mike

You are most welcome Mike. I’m glad to hear it’s working for you now.

Happy Deployments!
Michael