在TFS 2018发布步骤中如何复制构建生成的.nupkg到Drop文件夹
Got it, let's walk through exactly how to locate that StaticHelpers.1.0.0.nupkg file and copy it to your Drop folder for your release tasks. Here are two reliable methods you can use:
Method 1: Use TFS Built-in "Copy Files" Task
This is the simplest, no-code approach using TFS's native tasks:
- Add a new task to your release pipeline stage, search for and select the Copy Files task.
- Configure the task settings as follows:
- Source Folder: Enter the directory where your nupkg lives:
C:\agent_work\9\a\(you can also use the variable$(System.ArtifactsDirectory)here for a more flexible, non-hardcoded path). - Target Folder: Specify your Drop folder path, e.g.,
$(System.DefaultWorkingDirectory)/Dropor your team's dedicated Drop directory. - Contents: Input
StaticHelpers.1.0.0.nupkgto target the exact file. If you need to handle future version updates, use a wildcard likeStaticHelpers.*.nupkgto match all versions of the package.
- Source Folder: Enter the directory where your nupkg lives:
- Save your pipeline and run the release—this task will automatically copy the file to your desired location.
Method 2: Use a PowerShell Script Task
If you prefer more control over the copy process, a PowerShell script works great:
- Add a PowerShell task to your release pipeline stage.
- In the Script field, paste this command (replace the destination path with your actual Drop folder):
# Copy the specific nupkg to Drop folder Copy-Item -Path "C:\agent_work\9\a\StaticHelpers.1.0.0.nupkg" -Destination "C:\Your\Drop\Folder\Path" -Force
- The
-Forceflag ensures any existing file with the same name gets overwritten, preventing release failures due to duplicate files.
Pro Tip for Flexibility
To avoid hardcoding the agent work directory number (like 9 in your path), use TFS's predefined variables. For example, the $(System.ArtifactsDirectory) variable points directly to the build output directory (C:\agent_work\9\a\ in your case). Your PowerShell command would look like this:
Copy-Item -Path "$(System.ArtifactsDirectory)\StaticHelpers.1.0.0.nupkg" -Destination "$(System.DefaultWorkingDirectory)\Drop" -Force
This way, even if the agent work directory changes, your script stays valid.
内容的提问来源于stack exchange,提问作者RandomHandle

