title: Environment-specific configuration in app/web.config when implementing continuous deployment
body: <p><strong>TL;DR;</strong> </p>
  
  <p>How to manage environment-specific settings in app.config/web.config with Visual Studio &amp; TFS 2015 when implementing continuous deployment?</p>
  
  <p><strong>Full question</strong></p>
  
  <p>I am trying to implement continuous deployment for my C# Visual Studio 2015 solution using <a href="https://www.visualstudio.com/en-us/docs/build/overview" rel="nofollow noreferrer">the built-in feature in TFS 2015</a>. I'm currently wondering how should I proceed to setup settings in my configuration files that are environment-dependent (typically, DB connection string).</p>
  
  <p>I have basically 4 different environments: production, preproduction, UAT and integration. I'm not deploying to Azure or the cloud. Everything is on premises on servers within my company.</p>
  
  <p>I've tried to implement the solution proposed on <a href="http://www.colinsalmcorner.com/post/webdeploy-configs-and-web-release-management" rel="nofollow noreferrer">this link</a> but unless I misunderstood something, I feel that it means I would have to also tokenize my web.config and app.config inside my Visual Studio solution. I want to avoid that as I want to keep my - and my team mates' - experience as usual as possible. I don't want us having to modify yet another file to manage our configuration settings.</p>
  
  <p>I thought of using XML transform also, that would be triggered by a Powershell task during the deployment. Basically, I leave my config files as is and that task modifies the config files when triggered (as suggested on <a href="https://stackoverflow.com/questions/8989737/web-config-transforms-outside-of-microsoft-msbuild">this link</a>). But ideally, I'd like to use the built-in environment variables of the release. Additionally, that would mean my transform file would be checked-in as part of my solution. If I need to change it, I need to run a new build/deployment. I want to avoid that.</p>
  
  <p>So no solution is fully satisfying. I was wondering if some other tools or libraries were available that could do the job. I couldn't find anything. If there's nothing I guess I could come up with something with a Powershell task but if I can avoid reinventing the wheel...</p>
  
  <p>Last thing, I thought I could create in Visual Studio a new configuration based on the "Release" one that I would name - say - "Deployment". Then I'd use XML Transform on this configuration only to tokenize the configuration file and leave Debug and Release as is. In my TFS build I would use this configuration in order to deploy the tokenized configuration file as an artifact that I could finally update with a a Powershell script and environment variables like in the first link above. But it seems too complex and involves too many things. I'm sure there is something more simple that can be done.</p>
  
  <p>There is <a href="https://stackoverflow.com/questions/14515641/ci-and-deployment-with-tfs-and-powershell">this solution</a> also but it means 1 environment = 1 build. I absolutely want to avoid that. I want 1 build = deploy everywhere.</p>