简体   繁体   中英

Use environment variable in xml (in Azure ServiceDefinition xml)

Is it possible to use an environment variable inside the ServiceDefinition.csdef xml file itself?

I'm trying to achieve this:

  <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>

...

The create.cmd batch receives the parameters as string and doesn't get replaced with the actual deployment ID value.

Is it possible to achieve this?

Why do you need to pass in %DeploymentId% on the command line? You can just have the code in Create.cmd reference the %DeploymentId% environment variable.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM