How to access Service Configuration settings in Windows Azure Startup Task

In this example I will show you how you can access Service Configuration settings in Windows Azure Startup Task. The startup task is Startup.cmd which is launching another batch file name showconfvalues.cmd.


The Startup.cmd is as below:

cd /d “%~dp0”

Start /w showconfvalues.cmd


The showconfvalues.cmd is as below:

@echo on

@echo Your STRING 1 is: %CONFSTRING1%

@echo Your STRING 2 is: %CONFSTRING2%


The Windows Azure Application Service Definition file is as below:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureCmdApp" xmlns="">
<WorkerRole name="CmdWorkerRole" vmsize="ExtraSmall">
<Variable name="CONFSTRING1">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='SettingXYZ']/@value" />
<Variable name="CONFSTRING2">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='SettingABC']/@value" />
<ProgramEntryPoint commandLine="Startup.cmd" setReadyOnProcessStart="true" />
<InputEndpoint name="HttpIn" protocol="tcp" port="8999" />
<Setting name="SettingXYZ" />
<Setting name="SettingABC" />

The Windows Azure Application Service Configuration file is as below:

<?xml version="1.0"?>
<ServiceConfiguration xmlns:xsi="" xmlns:xsd="" serviceName="AzureCmdApp" xmlns="">
<Role name="CmdWorkerRole">
<Instances count="1" />
<Setting name="SettingXYZ" value="This is Setting 1 XYZ" />
<Setting name="SettingABC" value="This is Setting 2 ABC" />

You can launch this application from Windows Azure SDK Command prompt in the Administrator mode as below:


When running this application you will see the results showing your configuration values as below:

 Your STRING 1 is: This is Setting 1 XYZ

Your STRING 2 is: This is Setting 2 ABC


 Project Files:

  • build.cmd
  • pack.cmd
  • run.cmd
  • ServiceConfiguration.cscfg
  • ServiceDefinition.csdef
  • CmdWorkerRole <FOLDER>
    • Startup.cmd 
    • showconfvalues.cmd


Study more about xPath Values in Windows Azure


Download this this project from github as below:

Comments (2)

  1. Joe says:

    Does this only work in Azure SDK 1.5?

  2. Avkash Chauhan says:

    The support for XPATH element is started from Azure SDK 1.5 and newer so you can not use it with older SDK.