Skip to content

Instantly share code, notes, and snippets.

@robotdad
Last active April 29, 2024 04:37
Show Gist options
  • Save robotdad/83041ccfe1bea895ffa0739192771732 to your computer and use it in GitHub Desktop.
Save robotdad/83041ccfe1bea895ffa0739192771732 to your computer and use it in GitHub Desktop.
Installing VS C++ workloads with winget

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.

@KAI00101010
Copy link

According to https://learn.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2022 the product language is set via "--addProductLang ", there's a spurious space in the code on this page

@felipecrs
Copy link

Probably just

winget install Microsoft.VisualStudio.2022.Community --override "--quiet --add Microsoft.VisualStudio.Workload.NativeDesktop"

is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment