moswald
moswald

Reputation: 11667

Azure Cloud Service - no environment variables being set

The roles in my Cloud Service aren't getting any custom environment variables set. --Meaning if I enumerate the results of a call to Environment.GetEnvironmentVariables(), only the standard environment variables are set (things like PATH or the user id).

When I debug the Cloud Service locally using the emulator, the envvars are there, so I'm kind of at a loss here.

The relevant .csdef:

<WebRole name="..." vmsize="Small">
    <ConfigurationSettings>
      <Setting name="FirstSetting" />
      <Setting name="AnotherSetting" />
    </ConfigurationSettings>
    <Runtime>
      <Environment>
        <Variable name="FirstSettingEnvVar">
          <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='FirstSetting']/@value" />
        </Variable>
        <Variable name="SecondSettingEnvVar">
          <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='SecondSetting']/@value" />
        </Variable>
      </Environment>
    </Runtime>

and the relevant .cscfg:

<Role name="...">
    <Instances count="2" />
    <ConfigurationSettings>
      <Setting name="FirstSetting" value="ABCD" />
      <Setting name="SecondSetting" value="WXYZ" />
    </ConfigurationSettings>
</Role>

Upvotes: 2

Views: 478

Answers (1)

Max Power
Max Power

Reputation: 350

So I needed this set as I was trying to set an Environment variable from the web.config for linking to App Configuration (https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-dotnet-app).

Turns out I had to make a start up task for a batch file (elevated permission). Make it set the variables, then restart IIS via command line (as GUI didnt' work properly anyway): -

REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /v #KEY# /D #VAL#
iisreset /restart
net start w3svc

After that, hey presto it works. IIS will take the snapshot of the env host before it this tasks starts, so you have to restart it. Also, using the does not affect WebRole types of deployment as it's all within IIS rather than a process like WorkerRole types.

Upvotes: 0

Related Questions