简体   繁体   English

如何在 azure 批处理节点上安装 .net core?

[英]How to install .net core on azure batch node?

I am trying to install .net core 2.2 on azure batch node using start up task ?我正在尝试使用启动任务在 azure 批处理节点上安装 .net core 2.2 吗? The command that I am trying to use in startup task is below:我尝试在启动任务中使用的命令如下:

@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"

The startup task is failing.启动任务失败。 Moreover, if I run the script on the node manually, it is not installing .net core sdk.此外,如果我在节点上手动运行脚本,它不会安装 .net core sdk。

Any help?有什么帮助吗?

This might be the old question but I will write what worked for me.这可能是老问题,但我会写出对我有用的内容。 As Mike tried to do I also used the startup task and powershell script to install .net core on the Azure Batch Node.正如 Mike 尝试做的那样,我还使用启动任务和 powershell 脚本在 Azure Batch 节点上安装 .net 核心。

I verified, the dot net core does gets installed but at different location, and the path is not exported to environment variables but only used by the current process.我验证过,dot net core 确实安装了,但在不同的位置,并且路径没有导出到环境变量,而只被当前进程使用。 This is the reason it actually does not work这就是它实际上不起作用的原因

So I made 2 changes in above Start Task code所以我在上面的 Start Task 代码中做了 2 个更改

  1. Provide InstallDir where I want to Install .net core在我想安装 .net core 的地方提供 InstallDir
  2. Export the Path to Environment Variables.导出环境变量的路径。

Refer to the code below which made this thing work请参阅下面的代码使这件事起作用

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\\\""

After this, I am able to run my .net core code on the Machine在此之后,我可以在机器上运行我的 .net 核心代码

What Gour has said is correct. 古尔所说的是正确的。 You can install the setup file via resourceFiles in start task. 您可以在启动任务中通过resourceFiles安装安装文件。 From there, you can simply set up your starttask command line to first point to the start task working directory (where the file will be downloaded) and run the setup command. 从那里,您可以简单地设置starttask命令行以首先指向启动任务工作目录(将在该目录中下载文件)并运行setup命令。

Further explained here: https://docs.microsoft.com/en-us/azure/batch/batch-api-basics#start-task 此处进一步说明: https : //docs.microsoft.com/zh-cn/azure/batch/batch-api-basics#start-task

You can find the batch environment variables here: https://docs.microsoft.com/en-us/azure/batch/batch-compute-node-environment-variables . 您可以在此处找到批处理环境变量: https : //docs.microsoft.com/zh-cn/azure/batch/batch-compute-node-environment-variables It is recommended that you use them. 建议您使用它们。 If you use the explicit path of these directories, it can be changed by Microsoft at any time and that would introduce other issue when the nodes are rebooted, reimaged or if new nodes are allocated to the pool. 如果使用这些目录的显式路径,则Microsoft可以随时更改它的显式路径,这将在重新引导节点,重新映像节点或将新节点分配给池时引入其他问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将asp.net core 2.1预览应用程序部署到azure? 我如何在azure中安装新的sdk - How to deploy asp.net core 2.1 preview app to azure?? how do i install the new sdk in azure 如何以编程方式获取Azure批处理节点中的内核数? - How can I programmatically get the number of cores in an Azure Batch Node? 如何使用 .NET Framework C# 脚本安装 .NET Core? - How to install .NET Core with a .NET Framework C# script? 如何安装支持 .NET Core 6.0 的 .NET SDK? - How do I install a .NET SDK that supports .NET Core 6.0? .NET:如何将 Azure RetriableStreamImpl 转换为 ASP.Net Core IFormFile? - .NET: How to convert an Azure RetriableStreamImpl into an ASP.Net Core IFormFile? 如何在服务器核心上安装.NET Framework升级? - How do I install .NET Framework upgrades on Server Core? 如何在 .Net Core 项目中离线安装 nuget 包? - How to install nuget package as offline in .Net Core projects? 如何确定 WiX 安装所需的 .NET Core 3.1 运行时文件 - How to determine .NET Core 3.1 runtime files needed for WiX install 如何在 Linux (RHEL) 上离线安装 .NET Core 和 SDK? - How can I offline install .NET Core and SDK on Linux (RHEL)? 如何以编程方式在Azure VM上远程安装.NET 4客户端? - How can I remotely, programmatically install .NET 4 client on an Azure VM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM