以编程方式向"外部工具添加条目" Visual Studio 2017的菜单

时间:2017-07-26 19:02:13

标签: automation visual-studio-2017 envdte

是否有人知道是否可以在"外部工具"中添加条目?使用EnvDTE或任何其他方法的Visual Studio 2017菜单?到目前为止我唯一发现的是添加一些似乎不适用于VS2017的注册表项。

2 个答案:

答案 0 :(得分:3)

回答我自己的问题......

Axel Kemper在评论中对问题的链接最终将我带到了这个SO answer,它提供了一种非常简单的方法来将条目添加到外部工具列表。

基本上,您在IDE中生成所需的工具并使用"工具|导入和导出设置"将相应的设置导出到xml文件。在我的情况下,我得到以下内容:

<UserSettings>
  <ApplicationIdentity version="15.0"/>
  <ToolsOptions/>
  <Category name="Environment_Group" RegisteredName="Environment_Group">
    <Category name="Environment_ExternalTools" Category="{E8FAE9E8-FBA2-4474-B134-AB0FFCFB291D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_ExternalTools" PackageName="Visual Studio Environment Package">
      <ExternalTools>
        <UserCreatedTool>
          <Arguments>upload</Arguments>
          <CloseOnExit>true</CloseOnExit>
          <Command>c:\toolchain\make\make.exe</Command>
          <InitialDirectory>$(ProjectDir)</InitialDirectory>
          <IsGUIapp>false</IsGUIapp>
          <NameID>0</NameID>
          <Package>{00000000-0000-0000-0000-000000000000}</Package>
          <PromptForArguments>false</PromptForArguments>
          <SaveAllDocs>true</SaveAllDocs>
          <Title>neuteensy</Title>
          <Unicode>false</Unicode>
          <UseOutputWindow>true</UseOutputWindow>
          <UseTaskList>false</UseTaskList>
        </UserCreatedTool>
      </ExternalTools>
    </Category>
  </Category>
</UserSettings>

如有必要,可以手动或以编程方式调整文件中的设置。

您可以将文件传递给用户进行手动导入,也可以使用envDTE自动导入该文件,如链接答案所示。

答案 1 :(得分:1)

作为替代方案,我编写了以下cmd.exe脚本来加载和访问 Visual Studio 2017 的私有注册表:

@echo off
::
::  vsExtTools.cmd  -  Script to list external tools of Visual Studio 2017
::
::  Axel Kemper  29-Jul-2017  1st draft
::
setlocal

set VS_VERSION=15.0
set VS_APP_ROOT=%localappdata%\Microsoft
set DEBUG=1
set DEBUG=0

:: The RootSuffix for a normal VS installation will be blank. 
:: This is mostly used for the experimental instance 
:: cf  https://blog.agchapman.com/updating-registry-settings-for-visual-studio-2017/
set ROOT_SUFFIX=

call :findVSInstance %VS_APP_ROOT%\VisualStudio\%VS_VERSION% %ROOT_SUFFIX%
set REG_FILE=%VS_INSTANCE%\privateregistry.bin
if not exist "%REG_FILE%" goto no_reg

set HIVE_ROOT=HKLM\vsHive
call :trace Temporary registry hive %HIVE_ROOT%

::  administrative privileges are needed to load a hive
call :checkAdminRights
if [%IS_ADMIN%]==[0] goto xit

call :trace Loading registry hive from %REG_FILE%
reg.exe load %HIVE_ROOT% "%REG_FILE%"

call :trace %HIVE_ROOT%
reg.exe QUERY "%HIVE_ROOT%\Software\Microsoft\VisualStudio\%VS_HIVE%\External Tools" /s

:: Then you can use reg.exe to manipulate the hive

call :trace Unloading registry hive
reg.exe unload %HIVE_ROOT%

goto xit

:: ====================================================================
:findVSInstance
set VS_INSTANCE=
for /D %%D in (%1_*%2) do set VS_INSTANCE=%%D
for /D %%D in (%1_*%2) do set VS_HIVE=%%~nxD
call :trace VS Instance %VS_INSTANCE%
call :trace VS Hive %VS_HIVE%
goto :EOF

:: ====================================================================
:checkAdminRights
set IS_ADMIN=1
AT > NUL
IF %ERRORLEVEL% EQU 0 goto gotAdmin

call :grumble This script requires administrative privileges!
set IS_ADMIN=0
:gotAdmin
goto :EOF

:: ====================================================================
:grumble
echo.
echo %*
echo.
goto :EOF

:: ====================================================================
:no_reg
call :grumble Visual Studio %VS_VERSION% instance directory not found!
goto :xit

:: ====================================================================
:trace
if [%DEBUG%]==[1] (
echo %*
)
goto :EOF

:: ====================================================================
:xit
endlocal
pause

此版本需要管理员权限,只列出External Tool设置。可以添加对reg.exe的调用以创建新的工具设置条目。