Search code examples
azureconnection-stringapp-configazure-worker-rolesslowcheetah

Is there a way to use Slow Cheetah to transform app.config in Azure Worker Role?


I am trying to use Slow Cheetah to switch between a local db connection string and a SQL Azure connection string. This is in a Azure worker role that I am pushing to Azure with TeamCity. When I look through the log file the Slow Cheetah process is running correctly and is producing a transformed app.config but a future build step(that i don't think I can control) is over writing the transformed file with the original app.config.

Has anyone else had any success with this method or can you point me at another method to switch my connection strings. I was pointed towards just using one connection string and editing the hosts file to point at the db I wanted but that seems messy.


Solution

  • When dealing with production and testing/local environments for Azure, a best practice is to store such configuration information in the Service Configuration files instead of web.config. You can create as many Service Configuration files as you want, then select your desired .cscfg file by GUI or by cspack when publishing your solution. By default, the Azure templates in Visual Studio provide two .cscfg files:

    • ServiceConfiguration.Cloud.cscfg
    • ServiceConfiguration.Local.cscfg

    You can use these existing files to add two different connection string entries, or create your own. You can store the connection string value in the .cscfg file as shown below:

    <ConfigurationSettings>
      <Setting name="DbConnectionString" value="blah" />
    </ConfigurationSettings>
    

    Then, you can get the value of the configuration setting entry in your code as shown below:

    RoleEnvironment.GetConfigurationSettingValue("DbConnectionString")
    

    Relevant MSDN topics for this scenario below: