Azure DevOps发布构建工件失败求助:D:\a\1\a为空无法生成drop工件
That error is telling you exactly what's wrong: the artifact staging directory (D:\a\1\a, which maps to the $(Build.ArtifactStagingDirectory) variable) has no files in it when the PublishBuildArtifacts task runs. For your Dynamics 365 solution sync scenario, you're missing a critical step: exporting the solution from your source Dynamics instance to that staging directory before trying to publish it.
Here's how to fix this step-by-step:
1. Add a Dynamics 365 Solution Export Task First
You need to pull the solution from your source instance and save it to $(Build.ArtifactStagingDirectory) before the publish task. The easiest way is to use the official Power Platform DevOps task for exporting solutions. Add this above your PublishBuildArtifacts task in your YAML:
- task: Microsoft-PowerPlatform-Actions/export-solution@v0 inputs: environmentUrl: 'https://your-source-dynamics-instance.crm.dynamics.com' appId: '$(ServicePrincipalAppId)' appSecret: '$(ServicePrincipalSecret)' tenantId: '$(TenantId)' solutionName: 'YourTargetSolutionName' solutionOutputFile: '$(Build.ArtifactStagingDirectory)/YourSolution.zip' managed: false # Set to true if you're exporting a managed solution overwriteFiles: true displayName: 'Export Dynamics 365 Solution from Source Instance'
- You'll need to set up a service principal with permissions to export solutions from your source Dynamics instance, then store its
appId,appSecret, andtenantIdas pipeline variables (use secure variables for the secret to keep it safe). - Adjust
solutionNameandsolutionOutputFileto match your actual solution name and desired export path.
2. Verify the Staging Directory Has Content (For Debugging)
If you want to confirm the export worked before publishing, add a quick PowerShell task to list the contents of the staging directory. Insert this between the export and publish tasks:
- task: PowerShell@2 inputs: targetType: 'inline' script: | Write-Host "Contents of artifact staging directory:" Get-ChildItem -Path $(Build.ArtifactStagingDirectory) -Recurse $fileCount = (Get-ChildItem $(Build.ArtifactStagingDirectory) | Measure-Object).Count Write-Host "Total files found: $fileCount" displayName: 'Validate Staging Directory Contents'
This will log exactly what's in the directory, so you can confirm the solution zip file was exported successfully.
3. Confirm Your Publish Task Configuration
Your existing PublishBuildArtifacts task is correctly pointing to $(Build.ArtifactStagingDirectory), so no changes are needed here—as long as the export task puts files there. Just make sure it runs after the export task (YAML executes tasks top-to-bottom, so order matters).
4. Double-Check Pipeline Permissions
If the export task fails silently, make sure your service principal has the right permissions in the source Dynamics instance: it needs the System Administrator role or at least the Solution Import/Export privileges to pull the solution.
Once you add the export step, the staging directory will have your Dynamics 365 solution zip file, and the PublishBuildArtifacts task will no longer throw the "empty directory" error.
内容的提问来源于stack exchange,提问作者Shahroz Nawaz

