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.
msbuild : The term 'msbuild' is not recognized as the name of a cmdlet,
function, script file, or operable program.
+ FullyQualifiedErrorId : CommandNotFoundExceptionCommon 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.
- uses: microsoft/setup-msbuild@v2
- run: msbuild MySolution.sln /p:Configuration=ReleaseResolve MSBuild via vswhere
Find the install programmatically and call MSBuild by full path.
$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=ReleasePrefer dotnet build where possible
- For SDK-style projects, dotnet build uses the bundled MSBuild and needs no VS PATH setup.
- 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.