Installing Visual studio build tools worked locally but it is not working in target machine using provisoner

Varma 1,495 Reputation points
2024-02-18T08:06:06.6666667+00:00

I am using following script to install visual studi build tools 2022 which worked locally but in the locally it is not working in target machine , please suggest, there is no error message. I have tried to do multiple times, but after loging to the VM if i see it is not available. this is what I see from during provisoners running, I see below message for last 5 hours, it is there like that User's image

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
{count} votes

Accepted answer
  1. Martin Therkelsen 1,410 Reputation points MVP
    2024-02-18T19:29:15.61+00:00

    Hi Varma, This will work for you. Another hint is to use the HCL syntax highlighter in VS Code; this enables you to see if the syntax is correct without running the code.

    provisioner "powershell" {
        inline = ["Write-Host 'Installing Visual studio Build Tools...'",
          "New-Item -ItemType Directory -Path 'c:\\software'",
          "cd c:\\software",
          "Invoke-webRequest -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -UseBasicParsing -OutFile c:\\software\\vs_installer.exe",
          "Write-Host 'Starting installation with selected components...'",
          "$arguments = '--quiet --norestart --nocache --wait --noupdateInstaller --noweb --add \"Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools\" --add \"Microsoft.VisualStudio.Workload.WebBuildTools\" --add \"Microsoft.VisualStudio.Workload.AzureBuildTools\" --add \"Microsoft.VisualStudio.Workload.DataBuildTools\" -- includeRecommended'",
          "Start-Process c:\\software\\vs_installer.exe -Wait -ArgumentList $arguments"]
      }
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Martin Therkelsen 1,410 Reputation points MVP
    2024-02-18T08:58:21.6666667+00:00

    Hi Varma, You are breaking the syntax when splitting the lines like this in Packer. Could you put all the arguments on one line and try that instead?

    0 comments No comments

  2. Martin Therkelsen 1,410 Reputation points MVP
    2024-02-18T09:28:35.3466667+00:00

    Hi Varma, You are breaking the Packer syntax when splitting the command into lines as you do. Could you try to put the whole install command on one line?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.