Skipping Windows Azure Startup Tasks When Running in the Emulator

來源:互聯網
上載者:User

 http://blog.smarx.com/posts/skipping-windows-azure-startup-tasks-when-running-in-the-emulator

Startup tasks are often used in Windows Azure to install things or make other configuration changes to the virtual machine hosting your role code. Sometimes those setup steps are things you don’t want to execute when you’re running and testing locally via the compute emulator. (For example, you may want to skip a lengthy download or an installation of something you already have on your computer.)

With SDK 1.5, there are a few supported ways for code to determine whether or not it’s running emulated. From .NET code, there’s the new RoleEnvironment.IsEmulated static property. From other code (like a batch file startup task), SDK 1.5 adds a nice way to put the value of IsEmulated into an environment variable. Here’s the definition of a startup task that will get an EMULATED environment variable telling it whether or not the role is running under the compute emulator.

    <Startup>
      <Task executionContext="elevated" commandLine="startup\startup.cmd">
        <Environment>
          <Variable name="EMULATED">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
          </Variable>
        </Environment>
      </Task>
    </Startup>

Note the xpath attribute. There are many useful paths you can provide that will help you get at things like the port for an endpoint, the location of a local storage resource, or configuration setting values. See the MSDN documentation for the full details: “xPath Values in Windows Azure” and “WebRole Schema”.

Now all we need to do is make use of this environment variable in our startup task. The first line of startup.cmd simply checks the environment variable and immediately exit if it’s set to true:


if "%EMULATED%"=="true" goto :EOF

I used to write all sorts of tests in my startup tasks to try to avoid rerunning installers on my laptop, and this nice feature is going to save me the effort.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.