One approach is to use tokenization
In order to implement tokenization, you can use either of these two implementations
- https://github.com/qetza/vsts-replacetokens-task#readme
- https://marketplace.visualstudio.com/items?itemName=ms-devlabs.utilitytasks
If you decide to go with the first implementation, here are steps
Navigate to https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens and install "Replace Tokens" into the account you have your build def in.
Update the application web.config so that
connectionString="#{MyToken}#"
Add a new variable to the build definition with the name of the token. Ensure that value is PROTECTED
What will happen is that the build step will replace all the .config file tokens with the variable value specified for the build definition. Pretty neat.
Keep in mind that the integration tests would then likely FAIL for the source code repository in the state in which this task is not present. This might be annoying to some people, but is easy to get around if you use GIT and use a stash to override the token locally for integration tests.
Also, keep in mind that if you have a SQL Database(azure) with Firewall settings then the integration tests may fail due to the build agent virtual machines not having been authorized and you may need to add a new rule so that your build agent is authorized