Home > other >  Problems installing MS Build Tool updates via commandline
Problems installing MS Build Tool updates via commandline

Time:10-15

I'm using powershell to try automating some build tools update/installation for visual studio 2022 build tools on our build agents. In the UI its these 3 options that I need:

sql server build tools

I exported the config from the first server where I had installed this by hand, so I could get the IDs of the items to install:

{
  "version": "1.0",
  "components": [
    "Microsoft.VisualStudio.Component.Roslyn.Compiler",
    "Microsoft.Component.MSBuild",
    "Microsoft.VisualStudio.Component.CoreBuildTools",
    "Microsoft.VisualStudio.Workload.MSBuildTools",
    "Microsoft.Net.Component.4.7.2.TargetingPack",
    "Microsoft.Net.Component.4.8.TargetingPack",
    "Microsoft.VisualStudio.Component.SQL.SSDTBuildSku"
  ]
}

I used the 3 sku's at the bottom to create the script to try and install it:

$components =@(
    "Microsoft.Net.Component.4.7.2.TargetingPack",
    "Microsoft.Net.Component.4.8.TargetingPack",
    "Microsoft.VisualStudio.Component.SQL.SSDTBuildSku")
 $components | %{Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList 'modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" --passive --add $_' -Wait -PassThru}

This I know comes with a prompt for reboot through the UI, but I have rebooted post install and it doesn't show that these have been installed. I don't get any sort of confirmation that it was success or fail other than this output, though I do see the UI pop up briefly because i didn't specify silent:

script output

what have I done wrong?

CodePudding user response:

Swap the quotes in your -ArgumentList to outer double, and inner single. Interpolation doesn't occur inside single quotes so $_ isn't being expanded.

$components =@(
    "Microsoft.Net.Component.4.7.2.TargetingPack",
    "Microsoft.Net.Component.4.8.TargetingPack",
    "Microsoft.VisualStudio.Component.SQL.SSDTBuildSku")
 $components | %{Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList "modify --installPath 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools' --passive --add $_" -Wait -PassThru}

CodePudding user response:

following what Metzli_Tonaltzintli said, I tried something else and encased the download location in double-quotes and escaped it.

$components =@(
    "Microsoft.Net.Component.4.7.2.TargetingPack",
    "Microsoft.Net.Component.4.8.TargetingPack",
    "Microsoft.VisualStudio.Component.SQL.SSDTBuildSku")
$installTo = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
$components | %{Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList "modify --installPath `"$installTo`" --passive --add $_" -Wait -PassThru}

The moment I did this the UI popped up and actually shows a download status and reboots immediately after.

  • Related