【问题标题】:How to install .net core on azure batch node?如何在 azure 批处理节点上安装 .net core?
【发布时间】:2019-06-28 17:01:15
【问题描述】:

我正在尝试使用启动任务在 azure 批处理节点上安装 .net core 2.2?我在启动任务中尝试使用的命令如下:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Runtime dotnet -Version 2.2.5"

启动任务失败。此外,如果我在节点上手动运行脚本,它不会安装 .net core sdk。

有什么帮助吗?

【问题讨论】:

  • 您可以在批处理帐户的应用程序包中手动添加.net核心设置,然后添加启动任务以静默/安静地安装dotnet核心,并为启动任务提供应用程序包。另一种解决方法是,您可以在存储容器中添加 .net 核心设置,并获取 Blob 源(包括 SAS 令牌)和路径的完整 uri,并将其作为-ResourceFile 提供给启动任务以安装 .net 核心。安静安装模式:dotnet-runtime-2.2.5-win-x64.exe -q

标签: .net .net-core azure-batch


【解决方案1】:

古尔说的是对的。您可以在启动任务中通过 resourceFiles 安装设置文件。从那里,您可以简单地将您的 starttask 命令行设置为首先指向启动任务工作目录(将下载文件的位置)并运行 setup 命令。

在此进一步解释:https://docs.microsoft.com/en-us/azure/batch/batch-api-basics#start-task

您可以在此处找到批处理环境变量:https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables。建议您使用它们。如果您使用这些目录的显式路径,Microsoft 可以随时更改它,并且在重新启动节点、重新映像或将新节点分配到池时会引入其他问题。

例如:https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables#command-line-expansion-of-environment-variables

【讨论】:

    【解决方案2】:

    这可能是个老问题,但我会写出对我有用的东西。正如 Mike 尝试做的那样,我还使用启动任务和 powershell 脚本在 Azure Batch 节点上安装 .net core。

    我验证了,dot net core 确实安装了,但在不同的位置,并且路径没有导出到环境变量,但仅由当前进程使用。这就是它实际上不起作用的原因

    所以我在上面的启动任务代码中做了 2 处更改

    1. 在我要安装 .net core 的位置提供 InstallDir
    2. 将路径导出到环境变量。

    请参阅下面的代码,它使这件事起作用

    powershell "if(!([Environment]::GetEnvironmentVariable('Path', 'Machine') -split ';' -contains \"$Env:ProgramFiles\dotnet\\\")) {[Environment]::SetEnvironmentVariable('Path', \"$([Environment]::GetEnvironmentVariable('Path', 'Machine'));$Env:ProgramFiles\dotnet\\\",'Machine');}"
    powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Channel LTS -InstallDir \"$Env:ProgramFiles\dotnet\\\""
    

    之后,我可以在机器上运行我的 .net 核心代码

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多