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?
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?
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
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.
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!