1

I am trying to install .net core 2.2 on azure batch node using start up task ? 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.

Any help?

Mike143
  • 163
  • 3
  • 14
  • 1
    You can manually add .net core setup in Application Package in the Batch Account, then add a start task to silent/quiet install the dotnet core, and also provide the Application Package to the start task. Another workaround is that, you can add .net core setup in the storage container, and get Full uri of the Blob source (including SAS token) and path and provide it to the start task as `-ResourceFile` to install .net core. Quiet install mode: `dotnet-runtime-2.2.5-win-x64.exe -q` – Gour Gopal Aug 30 '19 at 11:22

2 Answers2

2

What Gour has said is correct. You can install the setup file via resourceFiles in start task. 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.

Further explained here: https://learn.microsoft.com/en-us/azure/batch/batch-api-basics#start-task

You can find the batch environment variables here: https://learn.microsoft.com/en-us/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.

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

1

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.

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. This is the reason it actually does not work

So I made 2 changes in above Start Task code

  1. Provide InstallDir where I want to Install .net core
  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

Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54