3

Does anybody know if it is possible to to add an entry to the "External Tools" menu of Visual Studio 2017 with EnvDTE or any other method? The only thing I found so far is to add some registry entries which doesn't seem to work for VS2017.

luni64
  • 321
  • 2
  • 8
  • Does that mean that VS2017 is using the keys in ..\14.0\External Tools? I assumed that this registry branch would only be read by VS2015. – luni64 Jul 26 '17 at 19:56
  • Have not grasped it myself, but [here](https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/extensibility/writing-to-the-user-settings-store.md) you can find an example how to access the `User Settings Store`. Looks rather envolved to me. – Axel Kemper Jul 26 '17 at 21:07
  • Visual Studio 2017 now stores its settings in a private registry file rather than in the common Windows registry. See this [related post](https://stackoverflow.com/questions/41119996/where-does-visual-studio-2017-rc-store-its-config) – Axel Kemper Jul 26 '17 at 21:26
  • Related (but not necessarily helpful): https://stackoverflow.com/questions/21340057/powershell-script-to-auto-add-visual-studio-external-tools-menu-options – CJBS Jan 05 '18 at 19:37

2 Answers2

7

Answering my own question...

The links from Axel Kemper in the comments to the question finally brought me to this SO answer which gives a really easy way to add an entry to the External Tools list.

Basically you generate the tool you need in the IDE and use "Tools|Import and Export Settings" to export the corresponding setting to an xml file. In my case I get the following:

<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>

If necessary it is easy to adjust the settings in the file manually or programmatically.

You can either pass the file to your users for manual import or you can automatically import it with envDTE as shown in the linked answer.

luni64
  • 321
  • 2
  • 8
  • This works. Export the tools settings as described, edit the XML to remove all but the options to be imported (as all entries in the tools list will be exported by default). Then use DTE to import. Additional details here: https://stackoverflow.com/a/34328236/3063884 – CJBS Jan 10 '18 at 06:42
  • Sorry to resurrect on old thread, but does this allow for updating an existing external tool without blowing away existing tools? – HeedfulCrayon Oct 25 '18 at 05:59
3

As an alternative, I have written the following cmd.exe script to load and access the private registry of 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

This version requires admin privileges and just lists the External Tool settings. Calls to reg.exe can be added to create new tool setting entries.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54