Path to MSBuild

Poking around the registry, it looks like


may be what you're after; fire up regedit.exe and have a look.

Query via command line (per Nikolay Botev)
reg.exe query "HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" /v MSBuildToolsPath
Query via PowerShell (per MovGP0)
dir HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\

You can also print the path of MSBuild.exe to the command line:

reg.exe query "HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" /v MSBuildToolsPath

Instructions for finding MSBuild:

  • PowerShell: &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
  • CMD: "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe

Instructions for finding VSTest:

  • PowerShell: &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.PackageGroup.TestTools.Core -find Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
  • CMD: "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.PackageGroup.TestTools.Core -find Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe

(Note that the instructions above are slightly modified from Microsoft's official ones. In particular, I've included the -prerelease flag to allow Preview and RC installations to be picked up, and the -products * to detect Visual Studio Build Tools installations.)

It only took over two years but finally in 2019, Microsoft has listened and given us a way to find these vital executables! If you have Visual Studio 2017 and/or 2019 installed, the vswhere utility can be queried for the location of MSBuild et al. Since vswhere is guaranteed by Microsoft to be located at %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe, there is no bootstrapping and no path hardcoding required anymore.

The magic is the -find parameter, added in version 2.6.2. You can determine the version you have installed by running vswhere, or checking its file properties. If you have an older version, you can simply download the latest one and overwrite the existing %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe.

vswhere.exe is a standalone executable, so you can download and run it from anywhere you have an internet connection. That means your build scripts can check if the environment they're running on is setup correctly, to name one option.

If you want to use MSBuild for .Net 4 then you can use the following PowerShell command to get the executable's path. If you want version 2.0 or 3.5 then just change the $dotNetVersion variable.

To run the executable you'll need to prepend the $msbuild variable with &. That will execute the variable.

# valid versions are [2.0, 3.5, 4.0]
$dotNetVersion = "4.0"
$regKey = "HKLM:\software\Microsoft\MSBuild\ToolsVersions\$dotNetVersion"
$regProperty = "MSBuildToolsPath"

$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"


For cmd shell scripting in Windows 7, I use the following fragment in my batch file to find MSBuild.exe in the .NET Framework version 4. I assume version 4 is present, but don't assume the sub-version. This isn't totally general-purpose, but for quick scripts it may be helpful:

set msbuild.exe=
for /D %%D in (%SYSTEMROOT%\Microsoft.NET\Framework\v4*) do set msbuild.exe=%%D\MSBuild.exe

For my uses I'm exiting the batch file with an error if that didn't work:

if not defined msbuild.exe echo error: can't find MSBuild.exe & goto :eof
if not exist "%msbuild.exe%" echo error: %msbuild.exe%: not found & goto :eof


  1. Cayson

    • 2019/1/7

    CMD: "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild - 

  2. Zayne

    • 2018/8/25

    How can I programatically get the path to MSBuild from a machine where my .exe is running? I can get the .NET version from the Environment but is there a way of getting the correct folder for a .NET

  3. Zane

    • 2020/10/17

    You can also use the following PowerShell module to locate MSBuild: vssetup.

  4. Bobby

    • 2017/5/13

    C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe. Microsoft's recommended way to launch it is with the Developer Command Prompt. Type "Developer Command Prompt" in the Windows 8 Start screen (or Windows 7 Start Menu), and you should see it listed.

  5. Bowen

    • 2020/7/19

    the folder's path that contains the MSBuild.exe to it (e.g., ;C:\Windows\Microsoft.NET\Framework64\v4.

  6. Aron

    • 2017/11/20

    You can also print the path of MSBuild.exe to the command line: reg.exe query "HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" /v MSBuildToolsPath

  7. Francisco

    • 2019/11/9

    For example, the path to MSBuild.exe installed with Visual Studio 2019 Community is C:\Program Files (x86)\Microsoft Visual 

  8. Maverick

    • 2016/7/8

    Path to MSBuild (Optional) Optionally supply the path to MSBuild: platform Platform (Optional) Specify the platform you want to build such as Win32, x86, x64 or any cpu. Tips: If you are targeting an MSBuild project (.*proj) file instead of a solution, specify AnyCPU (no whitespace).

  9. Santoro

    • 2016/6/26

    MSBuild is now installed in a folder under each version of Visual Studio. For example, C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild .

  10. Howard

    • 2019/8/15

    The path of the MSBuild subfolder under the \Program Files or \Program Files (x86) folder. The path always points to the 32-bit \Program Files (x86) folder on a 32-bit machine and \Program Files on a 64-bit machine.".

  11. Blaise

    • 2015/4/13

    This section lists the default MSBuild paths for Visual Studio and is intended for informational purposes only.

  12. Edgar

    • 2016/1/13

    The return value "C:\Path\To\VisualStudio\Root" seems useless, because we have to make an additional assumption reg. the location of MSBuild.exe inside that folder. We could append "\MSBuild\15.0\MSBuild\bin\MSBuild.exe", but that seems to defeat the purpose of not making assumptions/including hard coded paths in our build scripts.

  13. Gregory

    • 2017/5/25

    MSBuild -property installationFolder . The return value "C:\Path\To\VisualStudio\Root" seems useless, because we have to make an additional 

  14. Giuliani

    • 2017/3/9

    If you sort descending by InstallationVersion the first element will be latest version, then you can easily locate latest version of MsBuild.exe because you have the exact installation path of VS. Here is the full function: The function is really simple, it just uses the Get-VSSetupInstance to locate all visual studio installed version, sort by

  15. Owen

    • 2019/10/25

    The MSBuild.exe path depends on the .NET Framework version used to build your project. Typically you will want to call the most recent 

  16. Jeffrey

    • 2021/7/16

    To use this plugin, specify the location directory of MSBuild.exe on Jenkin's configuration page. The MSBuild executable is usually situated in 

  17. Maxwell

    • 2016/5/1

    MSBuild is now located inside the Visual Studio folder. For example: c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\ 

Comments are closed.

Recent Posts