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

2

5

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.

Interdependent answered 18/3, 2012 at 0:43 Comment(2)
If you are interested in this feature please vote for it at slowcheetah.uservoice.com/forums/185106-general/suggestions/…Prompter
Latest version of Slow Cheetah worked. Use Service Config if you can. But, my requirement was to integrate a custom config section from a third party product.Unfruitful
F
5

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:

Festinate answered 18/3, 2012 at 1:46 Comment(1)
This was a much simpler solution and I did end up using it and ditched my Slow Cheetah efforts. Kind of a hack but to support auto deploy to azure I just hardcoded the config filename into the build script. Thanks Monochrome.Interdependent
C
4

I agree with Monochrome that connection strings should be put in the Service Configuration, however there are situations where you need some configuration changes not related to connection strings that should be applied only when deploying to Azure. In a project of my own, for example, I needed some log4net configuration to change when deployed to Azure.

I found this article that explains how to make SlowCheetah work with a Worker Role project and Windows Azure. You need to make a small change to your Azure project file to copy the transformed configuration file.

<Target Name="CopyWorkerRoleConfigurations" BeforeTargets="AfterPackageComputeService">
    <Copy SourceFiles="..\WorkerRoleName\bin\$(Configuration)\WorkerRoleName.dll.config" DestinationFolder="$(IntermediateOutputPath)WorkerRoleName" OverwriteReadOnlyFiles="true" />
    </Target>
</Project>

You might have to tweak the SourceFiles attribute to fit your directory structure. But that's all there is to it.

Colleencollege answered 12/10, 2012 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.