Find MSBuild

Heath Stewart edited this page Nov 28, 2017 · 6 revisions

Find MSBuild

MSBuild is an optional component for Visual Studio and also installed with Build Tools. By default, vswhere will look for Community, Professional, and Enterprise editions of Visual Studio but you can optionally pass a list of products to search.

The following examples use the latest release. For examples that work with older releases, please view the history of this page.

With Visual Studio 2017 Update 2 or newer installed, you can find vswhere at %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe, or to make sure it's always available in your repo see Installing for an option using NuGet.


Note below that the examples are written as if in a batch script, which requires escaping "%" with another "%" which is why you see "%%i". If you were typing this in the command prompt you would use only one "%" like "%i".

@echo off

for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
  set InstallDir=%%i

if exist "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" (
  "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" %*


The following examples are equivalent to those above but written for PowerShell.

$path = vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
if ($path) {
  $path = join-path $path 'MSBuild\15.0\Bin\MSBuild.exe'
  if (test-path $path) {
    & $path $args

The asterisk indicates to search all products. It is not, however, a wildcard for pattern matching.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.