次の方法で共有


XPath で環境変数としてロール構成設定を公開する

重要

現在、Cloud Services (クラシック) は新しいお客様に対して非推奨となっており、2024 年 8 月 31 日に、すべてのお客様に対して廃止される予定です。 新しいデプロイでは、新しい Azure Resource Manager ベースのデプロイ モデル、 Azure Cloud Services (延長サポート) を使用してください。

クラウド サービス worker ロールまたは Web ロールのサービス定義ファイルで、ランタイム構成値を環境変数として公開できます。 次の XPath 値がサポートされています (これは API 値に対応します)。

これらの XPath 値は、 Microsoft.WindowsAzure.ServiceRuntime ライブラリ経由でも使用できます。

エミュレーターで実行中のアプリ

アプリがエミュレーターで実行されていることを示します。

Type
XPath xpath="/RoleEnvironment/Deployment/@emulated"
コード var x = RoleEnvironment.IsEmulated;

デプロイ ID

インスタンスのデプロイ ID を取得します。

Type
XPath xpath="/RoleEnvironment/Deployment/@id"
コード var deploymentId = RoleEnvironment.DeploymentId;

ロール ID

インスタンスの現在のロール ID を取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/@id"
コード var id = RoleEnvironment.CurrentRoleInstance.Id;

ドメインの更新

インスタンスの更新ドメインを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/@updateDomain"
コード var ud = RoleEnvironment.CurrentRoleInstance.UpdateDomain;

障害ドメイン

インスタンスの障害ドメインを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/@faultDomain"
コード var fd = RoleEnvironment.CurrentRoleInstance.FaultDomain;

ロール名

インスタンスのロール名を取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/@roleName"
コード var rname = RoleEnvironment.CurrentRoleInstance.Role.Name;

構成設定

指定した構成設定の値を取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='Setting1']/@value"
コード var setting = RoleEnvironment.GetConfigurationSettingValue("Setting1");

ローカル ストレージ パス

インスタンスのローカル ストレージ パスを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='LocalStore1']/@path"
コード var localResourcePath = RoleEnvironment.GetLocalResource("LocalStore1").RootPath;

ローカル ストレージ サイズ

インスタンスのローカル ストレージのサイズを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='LocalStore1']/@sizeInMB"
コード var localResourceSizeInMB = RoleEnvironment.GetLocalResource("LocalStore1").MaximumSizeInMegabytes;

エンドポイント プロトコル

インスタンスのエンドポイント プロトコルを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@protocol"
コード var prot = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].Protocol;

エンドポイント IP

指定したエンドポイントの IP アドレスを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@address"
コード var address = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Address

エンドポイント ポート

インスタンスのエンドポイント ポートを取得します。

Type
XPath xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='Endpoint1']/@port"
コード var port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Port;

@emulated xpath 値に設定された TestIsEmulated という環境変数でスタートアップ タスクを作成する worker ロールの例を次に示します。

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

次のステップ

ServiceConfiguration.cscfg ファイルの詳細を理解します。

ServicePackage.cspkg パッケージを作成します。

ロールの リモート デスクトップ を有効にします。