如何创建Visual Studio外部工具以执行TFS的‘Add Items to Folder...’命令?
I’ve set this up for my own team before, so here’s a straightforward, step-by-step guide that works for Visual Studio 2019 and 2022:
Step 1: Open External Tools Settings
- Launch Visual Studio
- Head to the Tools menu, then select External Tools... (if it’s missing from the main Tools menu, check under
Tools > Options > Environment > External Tools— the direct menu entry is usually enabled by default)
Step 2: Configure the New Tool
Click the Add button to create a new tool entry, then fill in these fields:
Title
Give it a clear, recognizable name like *TFS Add Items to Folder* (the asterisks help it stand out in the Tools menu)
Command
You have two solid options here, depending on whether you prefer the Visual Studio UI dialog or the TFS command-line prompt:
Option A: Trigger the Visual Studio UI Dialog
Use the Visual Studio executable to run its built-in command:
$(DevEnvDir)devenv.exe
Option B: Use tf.exe with a Selection Prompt
Use the TFS command-line tool directly (great for folks who prefer CLI workflows with a prompt):
$(DevEnvDir)CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe
Arguments
Match the arguments to your chosen command:
For Option A (UI Dialog):
/command "Team.AddItemsToFolder"
This tells Visual Studio to launch its native "Add Items to Folder" dialog — the same one you’d get from right-clicking in Solution Explorer.
For Option B (tf.exe Prompt):
add "$(SolutionDir)" /recursive /noignore /prompt
$(SolutionDir)targets your current solution’s root (swap this with$(ItemPath)if you want to target the item currently selected in Solution Explorer)/recursiveincludes all subfolders/noignorebypasses.tfignorerules (remove this if you want to respect ignored files)/promptopens a dialog to pick exactly which items to add
Initial Directory
Set this to ensure the tool runs in the right context:
$(SolutionDir)
Optional Checkboxes
- Check Use Output Window if you want to see command logs in Visual Studio’s Output pane (handy for debugging if things break)
- Skip Prompt for arguments unless you want to tweak parameters every time you run the tool (not needed for most use cases)
Step 3: Save and Test
Click OK to save the tool. Now you can run it from the Tools menu — it’ll either open the familiar "Add Items to Folder" dialog or prompt you to select items via the tf.exe interface, depending on your setup.
Quick Troubleshooting
- If
tf.exeisn’t found: Double-check the path — it varies slightly by Visual Studio edition (Community/Pro/Enterprise) and install directory. You can locate it manually by navigating to your Visual Studio install folder, thenCommon7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer. - If the UI command fails: Confirm you’re using
Team.AddItemsToFolder— this is the valid command name for recent Visual Studio versions. - Permissions issues: Make sure you have TFS permissions to add items to the target folder.
内容的提问来源于stack exchange,提问作者Joseph Schreifels

