Esporre le impostazioni di configurazione del ruolo come una variabile di ambiente con XPathExpose role configuration settings as an environment variable with XPath

Nel file di definizione del servzio del ruolo di lavoro o del ruolo Web del servizio cloud è possibile esporre i valori di configurazione di runtime come variabili di ambiente.In the cloud service worker or web role service definition file, you can expose runtime configuration values as environment variables. Sono supportati i valori XPath seguenti, che corrispondono ai valori di API.The following XPath values are supported (which correspond to API values).

Questi valori XPath sono disponibili anche tramite la libreria Microsoft.WindowsAzure.ServiceRuntime .These XPath values are also available through the Microsoft.WindowsAzure.ServiceRuntime library.

App in esecuzione nell'emulatoreApp running in emulator

Indica che l'app è in esecuzione nell'emulatore.Indicates that the app is running in the emulator.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/Deployment/@emulated"xpath="/RoleEnvironment/Deployment/@emulated"
CodiceCode var x = RoleEnvironment.IsEmulated;var x = RoleEnvironment.IsEmulated;

ID distribuzioneDeployment ID

Recupera l'ID distribuzione per l'istanza.Retrieves the deployment ID for the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/Deployment/@id"xpath="/RoleEnvironment/Deployment/@id"
CodiceCode var deploymentId = RoleEnvironment.DeploymentId;var deploymentId = RoleEnvironment.DeploymentId;

ID ruoloRole ID

Recupera l'ID del ruolo corrente per l'istanza.Retrieves the current role ID for the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/@id"xpath="/RoleEnvironment/CurrentInstance/@id"
CodiceCode var id = RoleEnvironment.CurrentRoleInstance.Id;var id = RoleEnvironment.CurrentRoleInstance.Id;

Aggiornamento dominioUpdate domain

Recupera il dominio di aggiornamento dell'istanza.Retrieves the update domain of the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/@updateDomain"xpath="/RoleEnvironment/CurrentInstance/@updateDomain"
CodiceCode var ud = RoleEnvironment.CurrentRoleInstance.UpdateDomain;var ud = RoleEnvironment.CurrentRoleInstance.UpdateDomain;

Dominio di erroreFault domain

Recupera il dominio di errore dell'istanza.Retrieves the fault domain of the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/@faultDomain"xpath="/RoleEnvironment/CurrentInstance/@faultDomain"
CodiceCode var fd = RoleEnvironment.CurrentRoleInstance.FaultDomain;var fd = RoleEnvironment.CurrentRoleInstance.FaultDomain;

Nome del ruoloRole name

Recupera il nome del ruolo dell'istanza.Retrieves the role name of the instances.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/@roleName"xpath="/RoleEnvironment/CurrentInstance/@roleName"
CodiceCode var rname = RoleEnvironment.CurrentRoleInstance.Role.Name;var rname = RoleEnvironment.CurrentRoleInstance.Role.Name;

Impostazione di configurazioneConfig setting

Recupera il valore dell'impostazione di configurazione specificata.Retrieves the value of the specified configuration setting.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='Setting1']/@value"xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='Setting1']/@value"
CodiceCode var setting = RoleEnvironment.GetConfigurationSettingValue("Setting1");var setting = RoleEnvironment.GetConfigurationSettingValue("Setting1");

Percorso di archiviazione localeLocal storage path

Recupera il percorso di archiviazione locale per l'istanza.Retrieves the local storage path for the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='LocalStore1']/@path"xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='LocalStore1']/@path"
CodiceCode var localResourcePath = RoleEnvironment.GetLocalResource("LocalStore1").RootPath;var localResourcePath = RoleEnvironment.GetLocalResource("LocalStore1").RootPath;

Dimensioni di archiviazione localeLocal storage size

Recupera le dimensioni di archiviazione locale per l'istanza.Retrieves the size of the local storage for the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='LocalStore1']/@sizeInMB"xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='LocalStore1']/@sizeInMB"
CodiceCode var localResourceSizeInMB = RoleEnvironment.GetLocalResource("LocalStore1").MaximumSizeInMegabytes;var localResourceSizeInMB = RoleEnvironment.GetLocalResource("LocalStore1").MaximumSizeInMegabytes;

Protocollo di endpointEndpoint protocol

Recupera il protocollo di endpoint per l'istanza.Retrieves the endpoint protocol for the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@protocol"xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@protocol"
CodiceCode var prot = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].Protocol;var prot = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].Protocol;

IP dell'endpointEndpoint IP

Ottiene l'indirizzo IP dell'endpoint specificato.Gets the specified endpoint's IP address.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@address"xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@address"
CodiceCode var address = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Addressvar address = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Address

Porta dell'endpointEndpoint port

Recupera la porta dell'endpoint per l'istanza.Retrieves the endpoint port for the instance.

TipoType EsempioExample
XPathXPath xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@port"xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@port"
CodiceCode var port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Port;var port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Port;

EsempioExample

Ecco un esempio di un ruolo di lavoro che crea un'attività di avvio con una variabile di ambiente denominata TestIsEmulated impostata sul valore @emulated xpath.Here is an example of a worker role that creates a startup task with an environment variable named TestIsEmulated set to the @emulated xpath value.

<WorkerRole name="Role1">
    <ConfigurationSettings>
      <Setting name="Setting1" />
    </ConfigurationSettings>
    <LocalResources>
      <LocalStorage name="LocalStore1" sizeInMB="1024"/>
    </LocalResources>
    <Endpoints>
      <InternalEndpoint name="Endpoint1" protocol="tcp" />
    </Endpoints>
    <Startup>
      <Task commandLine="example.cmd inputParm">
        <Environment>
          <Variable name="TestConstant" value="Constant"/>
          <Variable name="TestEmptyValue" value=""/>
          <Variable name="TestIsEmulated">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated"/>
          </Variable>
          ...
        </Environment>
      </Task>
    </Startup>
    <Runtime>
      <Environment>
        <Variable name="TestConstant" value="Constant"/>
        <Variable name="TestEmptyValue" value=""/>
        <Variable name="TestIsEmulated">
          <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated"/>
        </Variable>
        ...
      </Environment>
    </Runtime>
    ...
</WorkerRole>

Passaggi successiviNext steps

Altre informazioni sul file ServiceConfiguration.cscfg .Learn more about the ServiceConfiguration.cscfg file.

Creare un pacchetto ServicePackage.cspkg .Create a ServicePackage.cspkg package.

Abilitare Desktop remoto per un ruolo.Enable remote desktop for a role.