Skip to content

Instantly share code, notes, and snippets.

@stevensk
Last active September 23, 2017 18:16
Show Gist options
  • Save stevensk/e877829661c3295b006c to your computer and use it in GitHub Desktop.
Save stevensk/e877829661c3295b006c to your computer and use it in GitHub Desktop.
Azure Web.config Transforms & Continuous Deployment
// Scenario
We've got two Azure web sites (Staging and Production), each with their respective database and we want to deploy to both websites from the same Git repository using continuous deployment. We need to take advantage of config transforms to accommodate the differences between the two environments, such as connection strings, for example.
Continuous deployment is fairly straight-forward, as we can simply specify different branches for each enivronment. For example, using GitFlow, we can use the "develop" branch to deploy to our Acceptance or Staging environment and our "master" branch to deploy to our Production environment. This allows us to use Pull Requests as an approval workflow for automated contiuous deployment.
// Setup
1) To enable config transforms for a web application project, simply add a transform for each environment required, in this case "Staging":
Web.config
|- Web.Debug.config
|- Web.Release.config
|- Web.Staging.config
2) Now on Azure, go to the Configure tab for the website which represents this enviornment and add the following to App Settings:
Key=SCM_BUILD_ARGS
Value=-p:PublishProfile=Staging
Note that you can specify the build configuration by adding it to the build args. This is really useful if you need to do some remote debuggin on an Azure website, for example:
Key=SCM_BUILD_ARGS
Value=-p:Configuration=Debug;p:PublishProfile=Staging
Now when we push changes to our "develop" branch, continuos deployment will publish those changes to our Staging website and perform the appropriate config transforms as part of the build process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment