Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Replace ConnectionString values using transformations in Team Services

First off, check out this great overview

And be aware of how stinky-easy this is when deploying to Azure web sites.  Note: Creation of variables in Team Services, and slot settings in Azure are typically done by an Operations or Infrastructure/Deployment team, *not* by developers :).

  • Managed via Variables in Team Services:
  • Managed via Azure slot settings:

And also for IIS apps

But what about other app types that don’t have tasks that incorporate transforms?  It’s still easy, by using Colin’s ALM Build and Release Tools task. Specifically, the Replace Tokens task.

Here’s a quick walkthrough, using a Connection String value as an example.

  1. Create a variable in each environment with the name/value pair for the connection string. The “Name” must match the name of our connection string in web.config.
  2. Add the “Replace Tokens” task to the release. This will search all files with a .config extension and perform a match against any “names” that match an environment variable.
  3. In order to retain the ability to do easy debugging locally, keep the appropriate connection string setting in the web.config.
  4. Create “Debug” and “Release” configs that will tokenize the connection string when it is built by VSTS. In our case, it will replace the actual connectionstring value with “__DefaultConnectionString__” so that the replace tokens task from #2 will be able to find/replace it.

That’s it!  Debug locally using a local database (or whatever is appropriate), and have releases flow into the release pipeline where all other Connection strings will be populated based on the environment in Team Services, or the slot setting in Azure.


Share the post

Replace ConnectionString values using transformations in Team Services


Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription