I've been doing lots of Windows automation recently. My goal has been to be able to reproducibly create a Windows Server 2019-based Buildbot workers, first in a Vagrant environment, then later in AWS EC2 using pre-built images created with Packer. This task requires installing Visual Studio 2019 build tools automatically and fetching the project's dependencies with vcpkg automatically. It is possible to install Visual Studio 2019 with Chocolatey quite easily, but what if you need to install additional components to Visual Studio without using the Visual Studio installer GUI? Looking around did not quickly reveal any de facto instructions on how to do it, so this article aims to fill that gap.
First you need to locate your Visual Studio installer. In my case it was located in C:\Program Files (x86)\Microsoft Visual Studio\Installer, but yours may be in a different location. To find out where, launch an administrative Powershell prompt and do this:
PS C:\something> cd C:\ PS C:\> Get-Childitem -recurse -filter "vs_*.exe" --- snip ---- Directory: C:\Program Files (x86)\Microsoft Visual Studio\Installer Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 6/7/2021 9:41 AM 103304 vs_installer.exe -a---- 6/7/2021 9:41 AM 31160 vs_installer.windows.exe -a---- 6/7/2021 9:41 AM 103304 vs_installershell.exe -a---- 6/7/2021 9:41 AM 150936 vs_layout.exe --- snip ---
The key to installing new components is to use modify with the --add parameter. The --add parameter expects either a workload ID or component ID. The Visual Studio workload and component IDs contains links to all Visual Studio components per Visual Studio variant. Armed with all this information you're ready to craft a command-line:
PS C:\Program Files (x86)\Microsoft Visual Studio\Installer> .\vs_installer.exe modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Buildtools" --add Microsoft.VisualStudio.Component.Azure.AuthoringTools --downloadThenInstall --quiet
Explanation of the parameters:
- modify means we're modifying an existing installation
- --installPath must point to your Visual Studio installation. It must not end with a backslash or vs_installer.exe will choke.
- --add parameter determines what to install - it must be a valid component ID (see above)
- --downloadThenInstall does what is says on the tin
- --quiet ensures that we don't get any GUI crap popping up (use --passive if you want to see the GUI)
The interesting thing is that without either --quiet or --passive the Visual Studio installer will only select the components you added, not actually install them.