Windows Azure Cloud Service (24) 在模拟器中运行时跳过Windows Azure Startup任务

Windows Azure Platform 系列文章目录

  前一章里我们已经介绍了如何使用Windows Azure Startup来执行额外的配置任务,比如注册COM组件和注册Windows Service。

  另外,在Windows Azure SDK 1.5的时候,有新的API可以确定当前是否是在模拟器下运行。在.NET里有新的RoleEnvironment.IsEmulated静态属性。

  但是如果你在本地调试模拟器时,想在测试的时候不想执行Startup的步骤。我们改怎么办?

  我们看下面这个Startup节点:

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

  注意xpath 属性。你可以提供很多种有用的path,将帮助你获得如端点的端口、本地存储资源的位置或配置的setting值。详细信息请查看MSDN文档:“xPath Values in Windows Azure”“WebRole Schema”

  好,接下来是重点:如果我们在模拟器环境时,不想执行Startup的步骤,那么我们就修改(commandLine的内容)startup文件夹下的startup.cmd文件。

  在startup.cmd的第一行输入以下内容

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

  上面的代码意思是:如果侦测到是在模拟器状态,也就是ture,就立刻退出。

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

原文地址:https://www.cnblogs.com/threestone/p/2442823.html