Windows 如何从启动任务访问Azure本地存储? 在我的Azure角色启动任务中,我需要部署我的本地C++应用程序。我通过从.cmd文件运行一组操作来实现这一点

Windows 如何从启动任务访问Azure本地存储? 在我的Azure角色启动任务中,我需要部署我的本地C++应用程序。我通过从.cmd文件运行一组操作来实现这一点,windows,deployment,azure,cloud,local-storage,Windows,Deployment,Azure,Cloud,Local Storage,问题是,角色内容所在的E:\驱动器和启动任务运行的E:\驱动器只有大约1GB的可用空间,这不足以部署该应用程序 当然,我可以在服务定义中要求本地存储,但我找不到如何从启动任务中获取本地存储的实际位置路径-有RoleEnvironment.GetLocalResource可用于此目的,但它似乎只能从角色代码中获得,我需要从启动任务中执行同样的操作 如何从启动任务中检测到本地存储的路径?您可以编写C或PowerShell来执行此操作。现在,我首选的方法是以下PowerShell脚本: param($

问题是,角色内容所在的E:\驱动器和启动任务运行的E:\驱动器只有大约1GB的可用空间,这不足以部署该应用程序

当然,我可以在服务定义中要求本地存储,但我找不到如何从启动任务中获取本地存储的实际位置路径-有RoleEnvironment.GetLocalResource可用于此目的,但它似乎只能从角色代码中获得,我需要从启动任务中执行同样的操作


如何从启动任务中检测到本地存储的路径?

您可以编写C或PowerShell来执行此操作。现在,我首选的方法是以下PowerShell脚本:

param($name)
[void]([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime"))
write-host ([Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::GetLocalResource($name)).RootPath.TrimEnd('\\')
然后根据需要从批处理文件调用:

powershell -c "set-executionpolicy unrestricted"
for /f %%p in ('powershell .\getLocalResource.ps1 MyStorage') do set LOCALPATH=%%p

编辑:另请参见我的博客上的相同答案。

您可以编写C或PowerShell来完成此操作。现在,我首选的方法是以下PowerShell脚本:

param($name)
[void]([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime"))
write-host ([Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::GetLocalResource($name)).RootPath.TrimEnd('\\')
然后根据需要从批处理文件调用:

powershell -c "set-executionpolicy unrestricted"
for /f %%p in ('powershell .\getLocalResource.ps1 MyStorage') do set LOCALPATH=%%p

编辑:另请参见我的博客上的相同答案。

如果我没记错,我们正在使用。它很方便,如果您不熟悉PowerShell,就不必处理它的复杂性


现在我不是100%确定,但我记得它也有本地资源访问权限,所以您可以使用它。

如果我没记错的话,我们正在使用它。它很方便,如果您不熟悉PowerShell,就不必处理它的复杂性


目前我不能100%确定,但我记得它也有本地资源访问权限,因此您可以使用它。

如何从启动任务检测到本地存储的路径

在启动期间使用本地存储存储文件

<!-- Create the Local Storage used by the startup task. -->
    <LocalResources>
      <LocalStorage name="StartupLocalStorage" sizeInMB="5"/>
    </LocalResources>

    <Startup>
      <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
        <Environment>

          <!-- Create the environment variable that informs the startup task where to find its Local 
               Storage. %PathToStartupStorage% resolves to the fully qualified path to the location 
               of the Local Storage.-->
          <Variable name="PathToStartupStorage">
            <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='StartupLocalStorage']/@path" />
          </Variable>

        </Environment>
      </Task>
    </Startup>
您可以从启动脚本中使用本地环境变量PathToStartupStorage,%PathToStartupStorage%进行访问


更多参考:

如何从启动任务检测到本地存储的路径

在启动期间使用本地存储存储文件

<!-- Create the Local Storage used by the startup task. -->
    <LocalResources>
      <LocalStorage name="StartupLocalStorage" sizeInMB="5"/>
    </LocalResources>

    <Startup>
      <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
        <Environment>

          <!-- Create the environment variable that informs the startup task where to find its Local 
               Storage. %PathToStartupStorage% resolves to the fully qualified path to the location 
               of the Local Storage.-->
          <Variable name="PathToStartupStorage">
            <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='StartupLocalStorage']/@path" />
          </Variable>

        </Environment>
      </Task>
    </Startup>
您可以从启动脚本中使用本地环境变量PathToStartupStorage,%PathToStartupStorage%进行访问


更多参考信息,请参见:

另外值得一读的是如何定义启动脚本:另外值得一读的是如何定义启动脚本: