@echo off :: hMSBuild [Minified version] - v1.2.2.62992 [ 3ee58c3 ] :: Copyright (c) 2017 Denis Kuzmin [ entry.reg@gmail.com ] :: https://github.com/3F/hMSBuild setlocal enableDelayedExpansion set aa=1.0.62 set ab=%temp%\hMSBuild_vswhere set /a ac=0 set /a ad=0 set /a ae=0 set /a af=0 set /a ag=0 set /a ah=0 set "ai=" set "aj=" set ak=0 set al=2 set am=3 set "an=%* " set ao=%an:"=% set ap=%ao% set ap=%ap:-help =% set ap=%ap:-h =% set ap=%ap:-? =% if not "%ao%"=="%ap%" goto a_ goto ba :a_ echo. @echo :: hMSBuild [Minified version] - v1.2.2.62992 [ 3ee58c3 ] @echo Copyright (c) 2017 Denis Kuzmin [ entry.reg@gmail.com :: github.com/3F ] echo Distributed under the MIT license @echo https://github.com/3F/hMSBuild echo. @echo. @echo Usage: hMSBuild [args to hMSBuild] [args to msbuild.exe or GetNuTool core] echo ------ echo. echo Arguments: echo ---------- echo -novswhere - Do not search via vswhere. echo -novs - Disable searching from Visual Studio. echo -nonet - Disable searching from .NET Framework. echo -vswhere-version {num} - Specific version of vswhere. Where {num}: echo * Versions: 1.0.50 ... echo * Keywords: echo `latest` to get latest available version; echo `local` to use only local versions: echo (.bat;.exe /or from +15.2.26418.1 VS-build); echo. echo -nocachevswhere - Do not cache vswhere. Use this also for reset cache. echo -notamd64 - To use 32bit version of found msbuild.exe if it's possible. echo -eng - Try to use english language for all build messages. echo -GetNuTool {args} - Access to GetNuTool core. https://github.com/3F/GetNuTool echo -only-path - Only display fullpath to found MSBuild. echo -debug - To show additional information from hMSBuild. echo -version - Display version of hMSBuild. echo -help - Display this help. Aliases: -help -h -? echo. echo. echo -------- echo Samples: echo -------- echo hMSBuild -vswhere-version 1.0.50 -notamd64 "Conari.sln" /t:Rebuild echo hMSBuild -vswhere-version latest "Conari.sln" echo. echo hMSBuild -novswhere -novs -notamd64 "Conari.sln" echo hMSBuild -novs "DllExport.sln" echo hMSBuild vsSolutionBuildEvent.sln echo. echo hMSBuild -GetNuTool -unpack echo hMSBuild -GetNuTool /p:ngpackages="Conari;regXwild" echo. echo "hMSBuild -novs "DllExport.sln" || goto err" echo. echo --------------------- echo Possible Error Codes: ERROR_FILE_NOT_FOUND (0x2), ERROR_PATH_NOT_FOUND (0x3), ERROR_SUCCESS (0x0) echo --------------------- echo. exit /B 0 :ba call :bb an _is if [!_is!]==[1] goto bc set /a aq=1 & set ar=12 :bd if "!an:~0,11!"=="-GetNuTool " ( call :be %1 & shift goto bf ) if "!an:~0,11!"=="-novswhere " ( call :be %1 & shift set af=1 ) if "!an:~0,16!"=="-nocachevswhere " ( call :be %1 & shift set ag=1 ) if "!an:~0,6!"=="-novs " ( call :be %1 & shift set ad=1 ) if "!an:~0,7!"=="-nonet " ( call :be %1 & shift set ae=1 ) if "!an:~0,16!"=="-vswhereVersion " set as=1 if "!an:~0,17!"=="-vswhere-version " set as=1 if defined as ( set "as=" call :be %1 & shift set aj=%2 echo selected new vswhere version: !aj! call :be %2 & shift ) if "!an:~0,10!"=="-notamd64 " ( call :be %1 & shift set ac=1 ) if "!an:~0,5!"=="-eng " ( call :be %1 & shift chcp 437 >nul ) if "!an:~0,11!"=="-only-path " ( call :be %1 & shift set ai=1 ) if "!an:~0,7!"=="-debug " ( call :be %1 & shift set ah=1 ) if "!an:~0,9!"=="-version " ( @echo hMSBuild [Minified version] - v1.2.2.62992 [ 3ee58c3 ] exit /B 0 ) set /a "aq+=1" if !aq! LSS %ar% goto bd goto bc :be set an=!!an:%1 ^=!! call :bg an set "an=!an! " exit /B 0 :bc if "!ag!"=="1" ( call :bh "resetting cache of vswhere" rmdir /S/Q "%ab%" 2>nul ) if not "!af!"=="1" if not "!ad!"=="1" ( call :bi if "!ERRORLEVEL!"=="0" goto bj ) if not "!ad!"=="1" ( call :bk if "!ERRORLEVEL!"=="0" goto bj ) if not "!ae!"=="1" ( call :bl if "!ERRORLEVEL!"=="0" goto bj ) echo MSBuild tools was not found. Try to use other settings. Use key `-help` for details. exit /B %al% :bj call :bb a0 _is if [!_is!]==[1] ( echo Something went wrong. Use `-debug` key for details. exit /B %al% ) if defined ai ( echo !a0! exit /B 0 ) set at="!a0!" echo hMSBuild: !at! call :bh "Arguments: !an!" !at! !an! exit /B %ERRORLEVEL% :bi call :bh "trying via vswhere..." if defined aj ( if not "!aj!"=="local" ( call :bm call :bn exit /B !ERRORLEVEL! ) ) call :bo if "!ERRORLEVEL!"=="%am%" ( if "!aj!"=="local" ( exit /B %am% ) call :bm ) call :bn exit /B !ERRORLEVEL! :bo if exist "%~dp0vswhere.bat" set au="%~dp0vswhere" & exit /B 0 if exist "%~dp0vswhere.exe" set au="%~dp0vswhere" & exit /B 0 set av=Microsoft Visual Studio\Installer if exist "%ProgramFiles(x86)%\!av!" set au="%ProgramFiles(x86)%\!av!\vswhere" & exit /B 0 if exist "%ProgramFiles%\!av!" set au="%ProgramFiles%\!av!\vswhere" & exit /B 0 call :bh "local vswhere is not found." exit /B %am% :bm if "!ag!"=="1" ( set aw=%temp%\%random%%random%vswhere ) else ( set aw=%ab% ) call :bh "tvswhere: !aw!" if "!aj!"=="latest" ( set ax=vswhere ) else ( set ax=vswhere/!aj! ) call :bh "vswpkg: !ax!" if "!ah!"=="1" ( call :bp /p:ngpackages="!ax!:vswhere" /p:ngpath="!aw!" ) else ( call :bp /p:ngpackages="!ax!:vswhere" /p:ngpath="!aw!" >nul ) set au="!aw!\vswhere\tools\vswhere" exit /B 0 :bn call :bh "vswbin: "!au!"" for /f "usebackq tokens=1* delims=: " %%a in (`!au! -latest -requires Microsoft.Component.MSBuild`) do ( if /i "%%a"=="installationPath" set ay=%%b if /i "%%a"=="installationVersion" set az=%%b ) call :bh "vspath: !ay!" call :bh "vsver: !az!" if defined aw ( if "!ag!"=="1" ( call :bh "reset vswhere" rmdir /S/Q "!aw!" ) ) if [!az!]==[] ( call :bh "VS2017+ was not found via vswhere" exit /B %am% ) for /f "tokens=1,2 delims=." %%a in ("!az!") do ( set az=%%a.0 ) set a0=!ay!\MSBuild\!az!\Bin call :bh "found path to msbuild: !a0!" if exist "!a0!\amd64" ( call :bh "found /amd64" set a0=!a0!\amd64 ) call :bq exit /B 0 :bk call :bh "trying via MSBuild tools from Visual Studio - 2015, 2013, ..." for %%v in (14.0, 12.0) do ( call :br %%v Y & if [!Y!]==[1] exit /B 0 ) call :bh "msbvsold: unfortunately we didn't find anything." exit /B %al% :bl call :bh "trying via MSBuild tools from .NET Framework - .net 4.0, ..." for %%v in (4.0, 3.5, 2.0) do ( call :br %%v Y & if [!Y!]==[1] exit /B 0 ) call :bh "msbnetf: unfortunately we didn't find anything." exit /B %al% :br call :bh "checking of version: %1" for /F "usebackq tokens=2* skip=2" %%a in ( `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%1" /v MSBuildToolsPath 2^> nul` ) do if exist %%b ( call :bh "found: %%b" set a0=%%b call :bq set /a %2=1 exit /B 0 ) set /a %2=0 exit /B 0 :bf call :bh "direct access to GetNuTool..." call :bp !an! exit /B 0 :bq set a0=!a0!\MSBuild.exe if not "!ac!" == "1" ( exit /B 0 ) set a1=!a0:Framework64=Framework! set a1=!a1:amd64=! if exist "!a1!" ( call :bh "Return 32bit version of MSBuild.exe because you wanted this via -notamd64" set a0=!a1! exit /B 0 ) call :bh "We know that 32bit version of MSBuild.exe is important for you, but we found only this." exit /B 0 :bh if "!ah!"=="1" ( set a2=%1 set a2=!a2:~0,-1! set a2=!a2:~1! echo.[%TIME% ] !a2! ) exit /B 0 :bg call :a4 %%%1%% set %1=%a3% exit /B 0 :a4 set "a3=%*" exit /B 0 :bb setlocal enableDelayedExpansion set "a4=!%1!" if not defined a4 endlocal & set /a %2=1 & exit /B 0 set a4=%a4: =% set "a4= %a4%" if [^%a4:~1,1%]==[] endlocal & set /a %2=1 & exit /B 0 endlocal & set /a %2=0 exit /B 0 :bp setlocal disableDelayedExpansion @echo off :: GetNuTool - Executable version :: Copyright (c) 2015-2017 Denis Kuzmin [ entry.reg@gmail.com ] :: https://github.com/3F/GetNuTool set a5=gnt.core set a6="%temp%\%random%%random%%a5%" set "an=%* " set a=%an:~0,30% set a=%a:"=% if "%a:~0,8%"=="-unpack " goto bs if "%a:~0,9%"=="-msbuild " goto bt for %%v in (4.0, 14.0, 12.0, 3.5, 2.0) do ( for /F "usebackq tokens=2* skip=2" %%a in ( `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath 2^> nul` ) do if exist %%b ( set a7="%%b\MSBuild.exe" goto bu ) ) echo MSBuild was not found, try: gnt -msbuild "fullpath" args 1>&2 exit /B 2 :bt call :bv %1 shift set a7=%1 call :bv %1 :bu call :bw %a7% %a6% /nologo /p:wpath="%~dp0/" /v:m %an% del /Q/F %a6% exit /B 0 :bv call set an=%%an:%1 ^=%% exit /B 0 :bs set a6="%~dp0\%a5%" echo Generate minified version in %a6% ... :bw %a6% ^