When I use vs_buildTools.exe to install the vctools workload in a container and specify "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools" as the installation path, why does it end up installing to C:\Program automatically? How can I resolve th

Yang, Linfeng 20 Reputation points
2025-10-21T09:17:50.3866667+00:00
Start-Process .\vs_BuildTools.exe -ArgumentList '--quiet --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools"' -PassThru -Wait ; \

User's image

Developer technologies | Visual Studio | Setup
0 comments No comments
{count} votes

Answer accepted by question author
  1. Varsha Dundigalla(INFOSYS LIMITED) 2,700 Reputation points Microsoft External Staff
    2025-10-21T12:05:43.56+00:00

    Thank you for reaching out.

    The issue happens because PowerShell does not expand %ProgramFiles(x86)% that syntax works in CMD, not in PowerShell. When you pass it as-is, the installer sees an invalid path and truncates at the first space, creating C:\Program instead of the full folder.

    To fix this:

    Use PowerShell environment variable syntax: Replace %ProgramFiles(x86)% with $env:ProgramFiles(x86) so it expands correctly.

    Quote the full path: Wrap the entire path in quotes so spaces are preserved when passed to Start-Process.

    Example adjustment:

    --installPath "$env:ProgramFiles(x86)\Microsoft Visual Studio\2019\BuildTools"
    

    Compute the path first using Join-Path and store it in a variable, then pass that variable to --installPath. This avoids escaping issues.

    Reference:

    Use command-line parameters to install, update, and manage Visual Studio

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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