Skipping windows azure startup tasks when running in the emulator

Source: Internet
Author: 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 youDon'tWant 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 sdks 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 newRoleenvironment. isemulatedStatic Property. From other code (like a batch file startup task), sdks 1.5 adds a nice way to put the valueIsemulatedInto an environment variable. Here's the definition of a startup task that will getEmulatedEnvironment 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 >

NoteXpathAttribute. there are too 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 lineStartup. cmdSimply checks the environment variable and immediately exit if it's setTrue:

 
 
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.