This is a short outline of how to install the C++ workload with Visual Studio or the build tools using winget.
To find VS releases with winget use search.
winget search buildtools
The install command will install the VS installer with the core of the selected product installed. That isn't much. So if you use either of these commands to insll VS or the build tools you will need to launch the VS installer afterwards and select the relevant C++ workloads you need.
winget install Microsoft.VisualStudio.2022.BuildTools
winget install Microsoft.VisualStudio.2022.Community
Visual Studio does require elevation to install, so if those commands are not run from an elevated terminal you will be prompted to elevate.
You can pass details to the VS installer as part of a winget install command though. Specifically what you want is --override, "A string that will be passed directly to the installer."
As an examnple this command will install VS 2022 Community with the desktop C++ workload.
winget install Microsoft.VisualStudio.2022.Community --silent --override "--wait --quiet --add ProductLang En-us --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended"
Note that the above command uses --includeRecommended. You need to specify that to get all of the recmommended components with the workload, if you do not specify that the workload may not be functional. You can also specify --includeOptional which will additionally pull in everything in the workload. Of course you can use additional --add to include specific components in the workload.
VS command line parameters covers all of the options available for use.
Note that not every edition of VS has the same workloads or options available, so see this reference page to VS editions for specific component IDs
This is the VS Community component ID list
These are the IDs for my favorite C++ workloads.
- C++ desktop development workload: Microsoft.VisualStudio.Workload.NativeDesktop
- Linux and embedded workload: Microsoft.VisualStudio.Workload.NativeCrossPlat
If all you need are the compilers for a CI system this is the VS Build Tools component ID list
This is what you need for getting a working C++ environment.
- C++ desktop development workload: Microsoft.VisualStudio.Workload.VCTools
Note that the C++ desktop workloads above do include msbuild, msvc, and the Windows SDK.
Also, if you see a failure message with exit code 3010 that just means you need to reboot.
Probably just
is enough.