Content outdated
For up-to-date documentation see Tools for detecting and managing Visual Studio instances.How to find installed Visual Studio 2017 instances and C++ tools
There are multiple ways you can go about the finding the VS instances installed and determining the tools installed for each instance.
1. vswhere.exe: A stand-alone native executable that is redistributable and can be used to locate installed Visual Studio product instances for use in build and deployment scripts. The tool supports emitting different formats so far including plain text, JSON, and XML. For example, the following batch script for vswhere will find the root path the latest installed version that also contains the C++ Desktop workload:
for /f "usebackq tokens=1* delims=: " %%i in (`vswhere.exe -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop`) do (
if /i "%%i"=="installationPath" set dir=%%j
)
%dir% now contains the root installation path, if available.
2. PowerShell API: This is the simplest API for finding VS installation instances and components, but of course requires PowerShell v3 and above. If you are running on PowerShell v3 or v4, you will need to also install PowerShellGet. This is already included in PowerShell v5 that comes with Windows 10. The following command will list all installed VS2017 instances that also installed the v141 toolset for x86 and x64:
First install the VSSetup module:
Install-Module VSSetup -Scope CurrentUser
After that is completed, the following script will list all installed instances with Visual C++ compilers installed:
Get-VSSetupInstance | Select-VSSetupInstance -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64
3. Visual Studio Setup API: This COM API allows for querying installed VS instances and their components from a variety of programming languages (C++, C#, VB). The code is not as simple as the PowerShell script, but we have multiple examples on GitHub of how to consume the API:
Samples on GitHub (Sample with no NuGet dependency)
Example: Finding instances with an installed Visual C++ toolset with the API
For a more specific example of using this COM API from C++ to list installed instances that include Visual C++ tools, check out this sample on GitHub.
It is inside PrintPackageReference function that my sample checks the name of each installed component in the instance to determine if the Visual C++ toolset is installed (i.e. if “Microsoft.VisualStudio.Component.VC.Tools.x86.x64” is installed).
//check if instance has VC tools
if (bstrId == L"Microsoft.VisualStudio.Component.VC.Tools.x86.x64") {
vcToolsFound = true;
std::wcout << L"Instance " << OLE2T(vcInstance) << " contains the VC++ 2017 compiler tools (x86 and x64 targets).\n";
}
If you build the solution, a simple command prompt will launch that can list installed Visual Studio instances, their components, and which instances have C++ tools installed. To find the VC++ build tools on the machine with the tool, select option #3 in and it will indicate which instance have VC++ tools installed:
Note: This sample is not an official tool and is meant simply to instruct how to leverage the COM API to locate the installed Visual C++ tools.
C++ installation workloads and components
Below is a table of the underlying names used to describe each C++ workload, as well as the underlying component names used by the installer for the options provided in each workload. The Visual C++ 2017 v141 compiler toolset component (x86 and x64 targeting), known as Microsoft.VisualStudio.Component.VC.Tools.x86.x64, comes included in the desktop workload as a recommended (pre-selected) component and is a required (always installed) component in the C++ game and build tools workloads.
Workload | Installation Name |
Desktop development with C++ | Microsoft.VisualStudio.Workload.NativeDesktop |
Universal Windows Platform development | Microsoft.VisualStudio.Workload.Universal |
Linux development with C++ | Microsoft.VisualStudio.Workload.NativeCrossPlat |
Game development with C++ | Microsoft.VisualStudio.Workload.NativeGame |
Mobile development with C++ | Microsoft.VisualStudio.Workload.NativeMobile |
Build Tools Workloads
MSBuild tools | Microsoft.VisualStudio.Workload.MSBuildTools |
Visual C++ build tools | Microsoft.VisualStudio.Workload.VCTools |
Desktop development with C++
Friendly Name | Component Name |
VC++ 2017 v141 toolset (x86, x64) | Microsoft.VisualStudio.Component.VC.Tools.x86.x64 |
C++ profiling tools | Microsoft.VisualStudio.Component.VC.DiagnosticTools |
Windows 10 SDK (10.0.14393.0) | Microsoft.VisualStudio.Component.Windows10SDK.14393 |
Visual C++ tools for CMake | Microsoft.VisualStudio.Component.VC.CMake.Project |
Visual C++ ATL support | Microsoft.VisualStudio.Component.VC.ATL |
Windows 8.1 SDK And UCRT SDK | Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 |
Windows XP support for C++ | Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP |
MFC and ATL support (x86 and x64) | Microsoft.VisualStudio.Component.VC.ATLMFC |
C++/CLI support | Microsoft.VisualStudio.Component.VC.CLI.Support |
Clang/C2 (experimental) | Microsoft.VisualStudio.Component.VC.ClangC2 |
Standard Library Modules | Microsoft.VisualStudio.Component.VC.Modules.x86.x64 |
IncrediBuild | Component.Incredibuild |
Windows 10 SDK (10.0.10586.0) | Microsoft.VisualStudio.Component.Windows10SDK.10586 |
Windows 10 SDK (10.0.10240.0) | Microsoft.VisualStudio.Component.Windows10SDK.10240 |
Visual C++ 2015.3 v140 toolset (x86, x64) | Microsoft.VisualStudio.Component.VC.140 |
Universal Windows Platform development
*C++ Universal Windows Platform development tools are required to be installed for C++ UWP development but are not installed by default.
Friendly Name | Component Name |
IntelliTrace | Microsoft.VisualStudio.Component.IntelliTrace.FrontEnd |
Graphics debugger and GPU profiler for DirectX | Microsoft.VisualStudio.Component.Graphics.Tools |
*C++ Universal Windows Platform development tools | *Microsoft.VisualStudio.ComponentGroup.UWP.VC |
Windows 10 SDK (10.0.10240.0) | Microsoft.VisualStudio.Component.Windows10SDK.10240 |
Windows 10 SDK (10.0.10586.0) | Microsoft.VisualStudio.Component.Windows10SDK.10586 |
Architecture and analysis tools | Microsoft.VisualStudio.ComponentGroup.ArchitectureTools.Managed |
Game development with C++
Friendly Name | Component Name |
C++ profiling tools | Microsoft.VisualStudio.Component.VC.DiagnosticTools |
Windows 10 SDK (10.0.14393.0) | Microsoft.VisualStudio.Component.Windows10SDK.14393 |
Windows 10 SDK (10.0.10586.0) | Microsoft.VisualStudio.Component.Windows10SDK.10586 |
Windows 10 SDK (10.0.10240.0) | Microsoft.VisualStudio.Component.Windows10SDK.10240 |
Windows 8.1 SDK And UCRT SDK | Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 |
IncrediBuild | Component.Incredibuild |
Mobile development with C++
Friendly Name | Component Name |
Android NDK (RI 3B) | Component.Android.NDK.R13B |
Apache Ant (1.9.3) | Component.Ant |
Android SDK setup (API level 19 and 21) | Component.Android.SDK19 |
Android SDK setup (API level 22) | Component.Android.SDK22 |
Android SDK setup (API level 23) | Component.Android.SDK23 |
Java SE Development Kit (8.0920.14) | Component.JavaJDK |
C++ Android development tools | Component.MDD.Android |
Google Android Emulator (API Level 23) | Component.Android.Emulator |
Intel Hardware Accelerated Execution | Component.HAXM |
Android NDK (RI 3B) (32bit) | Component.Android.NDK.R13B_3264 |
Android NDK (R12B) | Component.Android.NDK.R12B |
Android NDK (R12B) (32bit) | Component.Android.NDK.R12B_3264 |
Android NDK (R11C) | Component.Android.NDK.R11C |
Android NDK (R11C) (32bit) | Component.Android.NDK.R11C_3264 |
C++ iOS development tools | Component.MDD.IOS |
IncrediBuild | Component.Incredibuild |
Visual C++ build tools
*The Visual C++ Build tools always installs the VS2017 v141 toolset.
Friendly Name | Component Name |
*VC++ 2017 v141 toolset (x86, x64) | Microsoft.VisualStudio.Component.VC.Tools.x86.x64 |
Windows 10 SDK (10.0.14393.0) | Microsoft.VisualStudio.Component.Windows10SDK.14393 |
Visual C++ tools for CMake | Microsoft.VisualStudio.Component.VC.CMake.Project |
Windows 8.1 SDK And UCRT SDK | Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 |
Visual C++ ATL support | Microsoft.VisualStudio.Component.VC.ATL |
MFC and ATL support (x86 and x64) | Microsoft.VisualStudio.Component.VC.ATLMFC |
C++/CLI support | Microsoft.VisualStudio.Component.VC.CLI.Support |
Clang/C2 (experimental) | Microsoft.VisualStudio.Component.VC.ClangC2 |
Standard Library Modules | Microsoft.VisualStudio.Component.VC.Modules.x86.x64 |
Windows 10 SDK (10.0.10586.0) | Microsoft.VisualStudio.Component.Windows10SDK.10586 |
Windows 10 SDK (10.0.10240.0) | Microsoft.VisualStudio.Component.Windows10SDK.10240 |
Setting up your command-line environment
The Developer Command prompt in Visual Studio 2017 can be used to set the path to the VC++ toolset in the VCToolsInstallDir environment variable. Now that we found have the path for each of the installed VS2017 instances that have VC++ compiler tools installed, we will refer to this directory as <VSInstanceDir>. This script is in the following location:
<VsInstanceDir>\Common7\Tools\vsdevcmd.bat [-arch=<tgt_arch>] [-host_arch=<host_arch>]
<tgt_arch> is the architecture upon which the produced binary will run (x86 [default], x64, arm).
<host_arch> is the architecture for which the compiler/linker was built (i.e. do you want cl.exe/link.exe, itself, to be able to make use of 32-bit or 64-bit address space) (x86 [default], x64).
Here is an example that will set up the command-line build environment to use the host-x64 compiler targeting x64, the following command would be used:
<VsInstanceDir>\Common7\Tools\vsdevcmd.bat -arch=x64 -host_arch=x64
We have now configured our command-line build environment so that it knows where the correct VC++ tools are based on our preferences(host/target).
Identifying the VC++ compiler tools version
In a world where multiple version of VC++ tools could be installed in a single VS instance, we have introduced the concept of <VCToolsVersion> which indicates the default version of VC++ tools for that VS installation instance. If you plan to manually assemble path to the VC++ toolset directory, we need to know the default version of the installed tools to get the full path.
The <VCToolsVersion> is found in one of two files that can be located once you have a <VSInstanceDir>.
<VsInstanceDir>\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.[txt|props]
You can check out the batch script located <VsInstanceDir>\Common7\Tools\vsdevcmd\ext\vcvars.bat as an example of how the VS Developer Command Prompt does this.
Once a <VCToolsVersion> value is identified, the full VC++ tools path can be manually constructed as follows:
<VsInstanceDir>\VC\Tools\MSVC\<VCToolsVersion>\bin\Host<host_arch>\<tgt_arch>
For our installed tools for host-x64 and target-x64, the path looks like:
<VSInstanceDir>\VC\ToolsMSVC\14.10.24930\bin\HostX64\x64
Closing remarks
Since we have removed the VS150COMNTOOLS registry key to support the new world where multiple VS instances of the same product can be installed side-by-side on the same machine, we know that many build systems and tools have relied on this in the past and the new options are not an identical replacement. We are actively working with library developers and others with builds that depend on the VC++ compiler tools, and we are open to further feedback to help refine and improve upon the solutions mentioned above. Please share any feedback you have in the comments or feel free to send more detailed suggestions to visualc@microsoft.com.
0 comments