Click here to monitor SSC

Theo Spears

Sharing configuration settings between Windows Azure roles

Published Wednesday, March 16, 2011 4:45 PM

If you are working on a medium-large Windows Azure project it's likely it will involve more than one role, for example separate web and worker roles. Unfortunately although all the windows azure configuration settings are stored in a single cscfg file, there is no way to share configuration settings between multiple roles. This means you have to duplicate common settings like connection strings across all your roles. There is an open Connect issue about this topic, but Microsoft have not said when they will fix it.

In the mean time I've put together a dirty dirty hack cunning workaround that creates a fake role containing your shared configuration settings, and copies it to all roles as part of the build process. Here's how you set it up:

1. Download the zip file attached to this post, and unzip it into the folder containing your Azure project (not your solution folder).

2. Edit your csdef and cscfg files to include the placeholder project

ServiceDefinition.csdef

<?xml version="1.0" encoding="utf-8"?> 
<ServiceDefinition
name="AzureSpendNotifier"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="GLOBAL">
<ConfigurationSettings>
<Setting name="ExampleSetting" />
</ConfigurationSettings>
</WorkerRole>
<WorkerRole name="MyWorker">
<ConfigurationSettings>
</ConfigurationSettings>
</WorkerRole>
<WebRole name="MyWeb">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="WebEndpoint" endpointName="WebEndpoint" />
</Bindings>
</Site>
</Sites>
<ConfigurationSettings>
</ConfigurationSettings>
</WebRole>
</ServiceDefinition>

ServiceConfiguration.cscfg

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration

serviceName="AzureSpendNotifier"

xmlns=http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration

osFamily="1" osVersion="*">
<Role name="GLOBAL">
<ConfigurationSettings>
<Setting name="ExampleSetting" value="Hello World" />
</ConfigurationSettings>
<Instances count="1" />
</Role>

<Role name="MyWorker">
<Instances count="1" />
<ConfigurationSettings>
</ConfigurationSettings>
</Role>
<Role name="MyWeb">
<Instances count="1" />
<ConfigurationSettings>
</ConfigurationSettings>
</Role>
</ServiceConfiguration>

It is important that all your roles contain a ConfigurationSettings entry in both cscfg and csdef files, even if it's empty- otherwise the shared configuration settings will not be inserted.

3. Open your azure deployment (.ccproj) project in notepad, and add the highlighted line below:

  ... 
<Import Project="$(CloudExtensionsDir)Microsoft.CloudService.targets" />
<Import Project="globalsettings/globalsettings.targets" />
</Project>

It is important you add this below the Microsoft.CloudService.targets import line, as it replaces some of the rules defined in that file.

Visual studio will prompt you to reload the project, say yes. At this point you will have a new Azure role called 'GLOBAL' with settings you can edit through the visual studio properties panel as normal. This role will never be deployed, but any settings you add to it will be copied to all your other roles when deployed or tested locally within visual studio.

Comments

No Comments
You need to sign in to comment on this blog

Post Categories

Latest articles
A first look at SQL Server 2012 Availability Group Wait Statistics
 If you are trouble-shooting an AlwaysOn Availability Group topology, a study of the wait statistics... Read more...

SQL Server Prefetch and Query Performance
 Prefetching can make a surprising difference to SQL Server query execution times where there is a high... Read more...

SSIS Basics: Setting Up Your Initial Package
 When working with databases, the use of SQL Server Integration Services (SSIS) is a skill that often... Read more...

Checking Out SQL Backup Pro 7’s New Automatic Backup Verification
 Wouldn't it be great to offload the daily chore of checking the integrity of your production... Read more...

Chuck Lathrope: DBA of the Day
 Chuck Lathrope was a finalist for the Exceptional DBA of the Year award in 2009. We contacted him to... Read more...