VSTS原生功能能否像Octopus Deploy一样部署NuGet Package至指定文件夹?
Great question! Yes, Azure DevOps (the rebranded version of VSTS) absolutely has native tools to do exactly what you’re asking—deploy contents from your VSTS-hosted NuGet packages to a specific folder on your deployment target, just like you did with Octopus Deploy. Here’s a step-by-step breakdown of how to set it up:
1. Fetch your NuGet package from the VSTS Feed
First, you need to pull the package from your organization’s feed into your pipeline’s working directory. You can use the native NuGet task for this:
- Add the NuGet task to your release pipeline (or build pipeline if you’re prepping artifacts first).
- Set the Command dropdown to
install(this is more direct thanrestoreif you’re targeting a single package, not project dependencies). - In the Arguments field, specify your package details and feed:
Note: You can pick your VSTS Feed from the dropdown in the task’s "Feeds to use" section to avoid hardcoding the source URL.YourPackageName -Version 1.0.0 -Source $(YourVSTSFeedName) -OutputDirectory $(System.DefaultWorkingDirectory)/packages
2. Extract the package contents to your target folder
Once the package is downloaded, you need to unpack its files. You have two native options depending on your needs:
Option A: Use the "Extract Files" task (no scripting required)
- Add the Extract Files task to your pipeline.
- Set Archive file patterns to the path of your downloaded
.nupkgfile. For example:$(System.DefaultWorkingDirectory)/packages/YourPackageName.1.0.0.nupkg - Specify the Destination folder as your target deployment path (e.g.,
C:\Deploy\MyAppfor Windows,/opt/myappfor Linux). - Check the Overwrite existing files box if you want to replace older content in the target folder.
Option B: Use a script for more control
If you need to filter specific files, run post-extraction steps, or handle edge cases, use a PowerShell (Windows) or Bash (Linux/macOS) task:
- PowerShell example:
# Extract the entire package to the target folder, overwriting existing files Expand-Archive -Path "$(System.DefaultWorkingDirectory)/packages/YourPackageName.1.0.0.nupkg" -DestinationPath "C:\Deploy\MyApp" -Force - Bash example:
# Unzip the package to the target directory unzip $(System.DefaultWorkingDirectory)/packages/YourPackageName.1.0.0.nupkg -d /opt/myapp
3. Deploy to remote targets (if applicable)
If your deployment target is a remote machine (not the pipeline agent itself), use Azure DevOps’ native file copy tasks to move the extracted files:
- For Windows targets: Use the Windows Machine File Copy task to transfer files from the agent’s working directory to the remote machine’s target folder.
- For Linux/macOS targets: Use the Copy Files Over SSH task to securely copy files to the remote server.
All these tasks are built into Azure DevOps—no third-party tools needed for basic deployment scenarios.
内容的提问来源于stack exchange,提问作者Calum

