Skip to content
Latchkey

Windows "msbuild is not recognized" (Developer Command Prompt) in CI

MSBuild was invoked but is not on PATH. MSBuild ships inside Visual Studio and is only on PATH within a Developer Command Prompt or after running the VS environment setup.

What this error means

Calling msbuild directly fails with CommandNotFoundException even though Visual Studio Build Tools are installed. Deterministic: msbuild is never on the plain PATH.

powershell
msbuild : The term 'msbuild' is not recognized as the name of a cmdlet,
function, script file, or operable program.
    + FullyQualifiedErrorId : CommandNotFoundException

Common causes

MSBuild is not on the default PATH

MSBuild.exe lives under the VS install (MSBuild\Current\Bin). It is only added to PATH inside the Developer Command Prompt, not in a default runner shell.

Multiple VS versions complicate resolution

With more than one VS edition or year installed, picking the right MSBuild by hand is error-prone; the wrong one or none is found.

How to fix it

Add MSBuild to PATH with the setup action

Use microsoft/setup-msbuild to locate and export MSBuild for later steps.

cmd
- uses: microsoft/setup-msbuild@v2
- run: msbuild MySolution.sln /p:Configuration=Release

Resolve MSBuild via vswhere

Find the install programmatically and call MSBuild by full path.

powershell
$vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
  -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
& $vs MySolution.sln /p:Configuration=Release

Prefer dotnet build where possible

  1. For SDK-style projects, dotnet build uses the bundled MSBuild and needs no VS PATH setup.
  2. Reserve full MSBuild for legacy project types that require it.

How to prevent it

  • Use setup-msbuild or vswhere to resolve MSBuild rather than assuming it is on PATH, and prefer dotnet build for SDK-style projects.

Frequently asked questions

What causes ""msbuild is not recognized""?
MSBuild.exe lives under the VS install (MSBuild\Current\Bin). It is only added to PATH inside the Developer Command Prompt, not in a default runner shell.
How do I fix "msbuild is not recognized"?
Use microsoft/setup-msbuild to locate and export MSBuild for later steps.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card