Sharing configuration settings between Windows Azure roles

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



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:

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.