MSBuild
Microsoft
Build Automation
Visual Studio
.NET Development

Where is MSBuild.exe located? Finding the MSBuild path

Codemia Knowledge Hub ·

There is no single fixed path to MSBuild.exe. With Visual Studio 2022 it is usually under C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\ (or the folder for your edition), and Visual Studio 2026 installs under a 18 folder instead of 2022, but the exact location depends on the edition, whether you installed Visual Studio or Build Tools, and whether you use older .NET Framework tooling or the dotnet workflow. In scripts, find it with vswhere.exe instead of hard-coding it.

Typical locations on modern Windows

powershell
C:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe

or:

powershell
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe

The edition folder can be Community, Professional, Enterprise or BuildTools. Older systems may use Program Files (x86) depending on the installed tooling.

Finding MSBuild with vswhere

Microsoft ships vswhere.exe specifically to locate Visual Studio components, and it is the most reliable approach for scripts that must work across developer machines and build agents:

powershell
1& "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
2  -latest `
3  -products * `
4  -requires Microsoft.Component.MSBuild `
5  -find MSBuild\**\Bin\MSBuild.exe

It returns the installed MSBuild path without guessing the edition or year.

Using the Developer Command Prompt

A Visual Studio Developer Command Prompt or Developer PowerShell usually puts MSBuild on PATH for that session, so you can run:

powershell
msbuild MySolution.sln /t:Build /p:Configuration=Release

This is convenient for interactive work because the environment is already set up for tool discovery, SDK lookup and other Visual Studio components. A regular shell does not get this setup.

dotnet build for SDK-style projects

Many modern .NET projects do not need MSBuild.exe called directly. dotnet build invokes the underlying build system and works across Windows, Linux and macOS:

bash
dotnet build MyApp.csproj -c Release

For SDK-style projects that do not rely on Visual Studio-specific targets, dotnet build is usually the better default. Direct MSBuild.exe calls still matter for older solutions, specialized targets and some enterprise build scripts.

The old .NET Framework path

Some examples point to a .NET Framework path:

powershell
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe

It exists on some systems but is often wrong for modern Visual Studio builds, because it may not match the toolset the solution expects, especially when the build depends on newer workloads or targets installed with Visual Studio.

Discovering MSBuild in a build script

A robust script finds MSBuild and fails clearly when it is missing:

powershell
1$msbuild = & "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
2  -latest `
3  -products * `
4  -requires Microsoft.Component.MSBuild `
5  -find MSBuild\**\Bin\MSBuild.exe | Select-Object -First 1
6
7if (-not $msbuild) {
8  throw "MSBuild was not found. Install Visual Studio Build Tools or Visual Studio."
9}
10
11& $msbuild "MySolution.sln" /t:Build /p:Configuration=Release

Build agents often have Build Tools installed with a different directory layout from developer workstations, so this is much safer than checking in a machine-specific absolute path.


Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms