Last active
August 2, 2017 23:37
-
-
Save renatoch/164a22b31993413028e873b8f0b6af17 to your computer and use it in GitHub Desktop.
Add an External Tool to Visual Studio up to VS 2015 (14.0) with a batch script (auto-detect next tool number)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo. | |
rem ======================================== | |
rem Configure desired Tool values and desired VS Versions (tested only for 14.0, other should be the same) | |
rem ======================================== | |
set VSVersions=13.0,14.0 | |
set ToolTitle=Abrir prompt testes front-end... | |
set ToolCmd=$(SolutionDir)\FrontendTestsPrepare.bat | |
set ToolDir=$(SolutionDir) | |
set ToolOpt=0x12 | |
set ToolArg= | |
set ToolSourceKey= | |
rem ======================================== | |
rem Logic begins | |
rem ======================================== | |
for %%a in ("%VSVersions:,=" "%") do ( | |
CALL:REGISTER_TOOL %%~a | |
) | |
exit /b | |
:REGISTER_TOOL | |
set VSToolRegKey=HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\%1\External Tools | |
echo Registering tool for VS %1 | |
rem ======================================== | |
rem Gets and sets tool count and new index | |
rem ======================================== | |
CALL:GETTOOLCOUNT "%VSToolRegKey%" | |
set ToolCount=%ERRORLEVEL% | |
echo Tool Index: %ToolCount% | |
set NewToolIndex=%ToolCount% | |
set /a NewToolCount=%ToolCount%+1 | |
rem ======================================== | |
rem Update Tool Count | |
rem ======================================== | |
reg add "%VSToolRegKey%" /v ToolNumKeys /f /t REG_DWORD /d 0x%NewToolCount% | |
rem ======================================== | |
rem Creates | |
rem ======================================== | |
reg add "%VSToolRegKey%" /v ToolTitle%NewToolIndex% /d "%ToolTitle%" | |
reg add "%VSToolRegKey%" /v ToolCmd%NewToolIndex% /d "%ToolCmd%" | |
reg add "%VSToolRegKey%" /v ToolDir%NewToolIndex% /d "%ToolDir%" | |
reg add "%VSToolRegKey%" /v ToolOpt%NewToolIndex% /d %ToolOpt% /t REG_DWORD | |
reg add "%VSToolRegKey%" /v ToolArg%NewToolIndex% /d "%ToolArg%" | |
reg add "%VSToolRegKey%" /v ToolSourceKey%NewToolIndex% /d "%ToolSourceKey%" | |
echo. | |
echo. | |
GOTO :EOF | |
:GETTOOLCOUNT | |
set ToolCount=0 | |
set RegQueryOutput= | |
rem Tests if registry path exists, returning 1 if not | |
reg query %1 /f ToolNumKeys /v > nul 2>&1 | |
IF NOT %ERRORLEVEL%==0 exit /b %ToolCount% | |
rem Gets tool count from reg query output | |
for /f "tokens=*" %%i in ('reg query %1 /f ToolNumKeys /v ^| findstr "0x.*"') do set RegQueryOutput=%%i | |
for /F "tokens=3 delims= " %%E in ("%RegQueryOutput%") do set ToolCount=%%E | |
set ToolCount=%ToolCount:0x=% | |
exit /b %ToolCount% | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment