After feedback on the VSSetup PowerShell module to query Visual Studio 2017 and related products, I’m pleased to say that a native, single-file executable is available on GitHub: vswhere. The VSSetup PowerShell module is also available on GitHub and provides a number of benefits for PowerShell scripts, but build tools and CMake and deployment scripts wanted a simple executable they could redistribute without spawning PowerShell.
You can enumerate instances with optional demands on which products, workloads, and components; and on which versions you require. Results can be printed in a variety of formats – currently colon-delimited plain text and JSON. If the query API isn’t registered, rather than erring no instances are assumed to be installed and results are empty, e.g. an empty array for JSON.
In a batch build script you could, for example, find MSBuild 15.0 by finding the latest, newest instance with MSBuild installed.
set ids=%pre%Community %pre%Professional %pre%Enterprise %pre%BuildTools
for /f "usebackq tokens=1* delims=: " %%i in (
vswhere -latest -products %ids% -requires Microsoft.Component.MSBuild -version [15.0,16.0)) do (
if /i "%%i"=="installationPath" set InstallDir=%%j
if exist "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" (
Current usage follows.
[code gutter=”false”]Visual Studio Locator, version 1.0.14-beta
Copyright (C) Microsoft Corporation. All rights reserved.
Usage: vswhere.exe [options]
-all Finds all instances regardless if they are complete.
-products arg One or more products to find. Defaults to Community, Professional, and Enterprise.
-requires arg One or more workloads or components required when finding instances.
-version arg A version range for instances to find. Example: [15.0,16.0) will find versions 15.*.
-latest Return only the newest version and last installed.
-format arg Return information about instances found in a format described below.
-nologo Do not show logo information. Some formats noted below will not show a logo anyway.
-?, -h, -help Display this help message.
json Colon-delimited properties in separate blocks for each instance (default).
text An array of JSON objects for each instance (no logo).[/code]