如何使用脚本或类似工具将外部工具添加到 Visual Studio?
How can I add an external tool to Visual Studio with a script or similar?
我们想为我们的开发人员将一些外部工具部署到 Visual Studio。有没有一种方法可以通过脚本或类似的方式将其自动化,或者他们都应该手动完成吗?
对于 Visual Studio 2013,外部工具在
的注册表中进行管理
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio.0\External Tools
您应该能够编写注册表脚本来添加您需要的内容。请确保在任何更新之前备份注册表。
有点晚了,但我在寻找同样的东西时偶然发现了这个问题,最后写了一个批处理文件来标识新的可用工具编号。
设置所需的 VS 版本以逗号分隔(适用于 VS 2015 - 14.0,VS 2017 使用私有注册表 - 参见 ),以及文件开头的工具参数。
@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%
可以在 "ToolOpt" 中进行或运算的标志如下(从 here 中提取):
#define TOOLOPT_ISAPPGUI 0x01
#define TOOLOPT_CLOSEONEXIT 0x02
#define TOOLOPT_PROMPTFORARGS 0x04
#define TOOLOPT_USEOUTPUTWIN 0x08
#define TOOLOPT_SAVEALLDOCS 0x10
#define TOOLOPT_USETASKLIST 0x20
#define TOOLOPT_UNICODE 0x40
我们想为我们的开发人员将一些外部工具部署到 Visual Studio。有没有一种方法可以通过脚本或类似的方式将其自动化,或者他们都应该手动完成吗?
对于 Visual Studio 2013,外部工具在
的注册表中进行管理HKEY_CURRENT_USER\Software\Microsoft\VisualStudio.0\External Tools
您应该能够编写注册表脚本来添加您需要的内容。请确保在任何更新之前备份注册表。
有点晚了,但我在寻找同样的东西时偶然发现了这个问题,最后写了一个批处理文件来标识新的可用工具编号。
设置所需的 VS 版本以逗号分隔(适用于 VS 2015 - 14.0,VS 2017 使用私有注册表 - 参见
@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%
可以在 "ToolOpt" 中进行或运算的标志如下(从 here 中提取):
#define TOOLOPT_ISAPPGUI 0x01
#define TOOLOPT_CLOSEONEXIT 0x02
#define TOOLOPT_PROMPTFORARGS 0x04
#define TOOLOPT_USEOUTPUTWIN 0x08
#define TOOLOPT_SAVEALLDOCS 0x10
#define TOOLOPT_USETASKLIST 0x20
#define TOOLOPT_UNICODE 0x40