You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure Pipelines中扁平化报表项目的MSBuild生成输出目录结构

实现需求的两种可选方案

方案1:仅调整Copy Files任务(适合项目数量固定的场景)

你可以为每个项目单独配置复制规则,直接跳过bin/Release层级,修改后的Copy Files任务配置如下:

  • Source folder: $(build.sourcesdirectory)
  • Contents: 按项目逐行添加规则,示例如下:
Project A\bin\$(BuildConfiguration)\*.rdl
Project B\bin\$(BuildConfiguration)\*.rdl
  • Target folder: $(Build.ArtifactStagingDirectory)
  • 保持Flatten Folders参数为关闭状态:false
  • 高级参数中设置MatchPatternRecurse: false

这种方案的优势是不需要加额外任务,缺点是新增项目时需要同步修改复制规则。

方案2:添加PowerShell任务(通用灵活,适合项目数量多或经常变动的场景)

保留现有Build、Copy Files任务不变,在Copy Files任务之后、Publish artifact任务之前新增一个PowerShell任务,写入以下执行脚本:

$artifactPath = "$(Build.ArtifactStagingDirectory)"
# 遍历所有rdl文件,整理到对应项目文件夹
Get-ChildItem -Path $artifactPath -Recurse -Filter "*.rdl" | ForEach-Object {
    $pathSegments = $_.FullName.Replace($artifactPath, '').Trim('\').Split('\')
    $projectName = $pathSegments[0]
    $targetDir = Join-Path $artifactPath $projectName
    
    if (-not (Test-Path $targetDir)) {
        New-Item -ItemType Directory -Path $targetDir | Out-Null
    }
    Move-Item -Path $_.FullName -Destination $targetDir -Force
}
# 清理残留的bin文件夹
Get-ChildItem -Path $artifactPath -Directory -Filter "bin" -Recurse | Remove-Item -Recurse -Force

执行完这个脚本后,$(Build.ArtifactStagingDirectory)下的目录结构就会完全符合你的要求,直接执行后续的Publish artifact任务即可。


内容的提问来源于stack exchange,提问作者Angler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 03:15:04