【问题标题】:Programmatically add an entry to the "External tools" menu of Visual Studio 2017以编程方式向 Visual Studio 2017 的“外部工具”菜单添加一个条目
【发布时间】:2017-07-26 19:02:12
【问题描述】:

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

【问题讨论】:

  • 这是否意味着VS2017正在使用..\14.0\External Tools中的键?我假设这个注册表分支只会被 VS2015 读取。
  • 我自己没有掌握,但是here你可以找到一个如何访问User Settings Store的例子。在我看来相当投入。
  • Visual Studio 2017 现在将其设置存储在私有注册表文件中,而不是常见的 Windows 注册表中。看到这个related post
  • 相关(但不一定有帮助):stackoverflow.com/questions/21340057/…

标签: automation visual-studio-2017 envdte


【解决方案1】:

回答我自己的问题...

cmets 中 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 自动导入它,如链接答案所示。

【讨论】:

  • 这行得通。按照描述导出工具设置,编辑 XML 以删除除要导入的选项之外的所有选项(因为默认情况下将导出工具列表中的所有条目)。然后使用 DTE 导入。此处的其他详细信息:stackoverflow.com/a/34328236/3063884
  • 很抱歉在旧线程上复活,但这是否允许在不破坏现有工具的情况下更新现有的外部工具?
【解决方案2】:

作为替代方案,我编写了以下 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 的调用以创建新的工具设置条目。

【讨论】:

    猜你喜欢
    • 2017-08-02
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多