2

I need to use msbuild from a .cmd file to build my solution.

Of course it seems to be installed in different directories on different machine setups, using from the cmd, how can I find the installed path to msbuild.exe?

shenku
  • 11,969
  • 12
  • 64
  • 118

3 Answers3

2

On my scripts I always use this path: %windir%\microsoft.net\framework\vxxx\msbuild.exe

(replace xxx with the framework desired version number).

or you can follow "the hard way": read the install location from the registry: Path to MSBuild

Community
  • 1
  • 1
Manuel Spezzani
  • 1,041
  • 7
  • 15
1

Try this one:

"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -nologo -latest -property installationPath > temp.txt
set /p $MSBUILDROOT=<temp.txt
del temp.txt

"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationVersion > temp.txt
set /p $MSBUILDVER=<temp.txt
del temp.txt

set $MSBUILDPATH=%$MSBUILDROOT%\MsBuild\%$MSBUILDVER:~0,2%.0\Bin\MSBuild.exe

$MSBUILDPATH should be you MsBuild full path.

Raul Kist
  • 331
  • 3
  • 8
0

This works with newer versions that use 'Current' instead of version.

setlocal EnableDelayedExpansion
echo Locating msbuild.exe
set VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
for /f "tokens=1 delims=;" %%i in ('"!VSWHERE!" -nologo -latest -property installationPath') do SET "MSBUILDROOT=%%i"
for /f "tokens=1" %%i in ('"!VSWHERE!" -property installationVersion') do SET "MSBUILDVER=%%i"
set MSBUILDPATH="!MSBUILDROOT!\MSBuild\!MSBUILDVER:~0,2!.0\Bin\MSBuild.exe"
if not exist "!MSBUILDPATH!" set MSBUILDPATH="!MSBUILDROOT!\MSBuild\Current\Bin\amd64\MSBuild.exe"
if not exist "!MSBUILDPATH!" set MSBUILDPATH="!MSBUILDROOT!\MSBuild\Current\Bin\MSBuild.exe"
echo Found MSBuild at !MSBUILDPATH!
Nick
  • 1
  • 1