在xml中使用环境变量(在Azure ServiceDefinition xml中)

时间:2014-01-22 12:50:40

标签: c# .net xml azure environment-variables

是否可以在ServiceDefinition.csdef xml文件中使用环境变量?

我正在努力实现这个目标:

  <ServiceDefinition name="MyService"    xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2013-03.2.0">
 <WorkerRole name="MyService" vmsize="Small">
<Startup>
  <Task commandLine="Create.cmd config_%DeploymentId%" executionContext="elevated" taskType="simple" >
    <Environment>
      <Variable name="DeploymentId">
        <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='DeploymentId']/@value" />
      </Variable>
    </Environment>          
  </Task>

...

create.cmd批处理以字符串形式接收参数,不会被实际的部署ID值替换。

有可能实现这个目标吗?

2 个答案:

答案 0 :(得分:0)

为什么需要在命令行上传入%DeploymentId%?您可以让Create.cmd中的代码引用%DeploymentId%环境变量。

答案 1 :(得分:0)

本文可能会有所帮助,包含有关在CSDEF中设置环境变量的教程:http://blog.toddysm.com/2011/03/what-environment-variables-can-you-use-in-windows-azure.html