如何在vNext Build中仅获取部分Shelveset?
Great question—this is a common pain point with TFVC gated check-ins when you're trying to scope builds to specific directories. Let's break down what's going on and the solutions you can use:
Core Issue
The default GetSources task in vNext Build doesn't expose a built-in setting to specify an itemSpec for partial unshelving, which is why you're hitting folder mapping errors when your shelveset includes changes in unmapped directories like Documents.
Workaround Solutions
1. Cloak the Unmapped Directory in Your Build Workspace
The simplest fix is to adjust your build definition's workspace mapping to cloak the Documents directory. This tells the GetSources task to ignore changes in that directory during unshelving, without needing to map it fully:
- Open your build definition, go to the Repository tab
- Under Workspace, click Edit
- Add a new mapping for
$/YourProject/Documentsand set the Type toCloak - Save the definition, and future gated builds will skip unshelving changes in the cloaked directory
2. Replace Default GetSources with a Custom tf unshelve Script
If you need full control over what gets unshelved, disable the default GetSources task and use a custom script (PowerShell or Command Line) to run the tf unshelve command with your desired itemSpec:
- In your build definition, go to the Get sources section and disable the task (uncheck the box next to it)
- Add a Command Line task with the following command (adjust paths to match your TFVC project):
tf unshelve /s:http://your-tfs-server:8080/tfs/YourCollection "$(Build.SourcesShelvesetName)" /itemSpec:"$/YourProject/Sources/*" /recursive - Optional: Add a prior task to initialize the build workspace if needed (use
tf workspaceandtf getcommands to set up the base workspace before unshelving)
3. Restrict Gated Check-In Triggers to Only the Sources Directory
Another approach is to limit which changes trigger your gated build definition, so changes to Documents never hit this build in the first place:
- Go to your Team Project's Settings > Version Control > Check-in Policies
- Edit the Gated Check-in policy, select your build definition
- Click Filter paths and add an include rule for
$/YourProject/Sources/*, then exclude any other paths you don't want to trigger the build - Save the policy—now only changes in the Sources directory will trigger this gated build, avoiding the unmapped directory issue entirely
Key Note
As of the latest vNext Build versions, there's still no native UI setting in the GetSources task to specify an itemSpec for partial unshelving. The workarounds above are the recommended ways to handle this scenario.
内容的提问来源于stack exchange,提问作者huserben

