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

如何在VSTS构建后将类图发布至TFS项目页面?

提取并发布类图到Azure DevOps项目页面的简便方案

Great question—this is a common need for keeping stakeholders aligned with code architecture. Here's a step-by-step approach to automate extracting your class diagrams and publishing them to your Azure DevOps (formerly VSTS/TFS) project after every build:

第一步:从代码中提取类图

Assuming your class diagrams are stored as Visual Studio .cd files in your codebase, you have two simple options to export them to viewable formats (like PNG or HTML):

选项1:用Visual Studio命令行导出(最直接)

If your build agent has Visual Studio or Visual Studio Build Tools installed, you can use devenv.exe to export diagrams directly in your pipeline:

  1. Add a Command Line task to your build pipeline.
  2. Use this command (adjust paths to match your solution and diagram location):
devenv.exe $(Build.SourcesDirectory)/YourSolution.sln /command "ClassDiagram.ExportDiagram YourProject/ClassDiagrams/OrderSystem.cd /output:$(Build.ArtifactStagingDirectory)/OrderSystem.png /format:png"
  1. For multiple diagrams, wrap this in a PowerShell script to batch process all .cd files:
$outputDir = "$(Build.ArtifactStagingDirectory)/ClassDiagrams"
mkdir $outputDir -Force

# Find all .cd files in your repo
$diagramFiles = Get-ChildItem -Path $(Build.SourcesDirectory) -Filter *.cd -Recurse

foreach ($file in $diagramFiles) {
    $relativePath = $file.FullName.Substring($(Build.SourcesDirectory).Length + 1)
    $outputFile = Join-Path $outputDir "$($file.BaseName).png"
    devenv.exe $(Build.SourcesDirectory)/YourSolution.sln /command "ClassDiagram.ExportDiagram $relativePath /output:$outputFile /format:png"
}

选项2:使用预导出的图片(最省心)

If your team already exports class diagrams to PNG/JPG alongside the .cd files, just add a Copy Files task to copy these images to $(Build.ArtifactStagingDirectory)—no extra conversion needed.


第二步:发布到Azure DevOps项目页面

Once you have your diagram files in the build artifact staging directory, choose where to publish them:

发布到Wiki(推荐给分析师/测试人员查阅)

Azure DevOps Wiki supports Markdown, so you can automate updating a dedicated page with your diagrams:

  1. First, add a Publish Build Artifacts task to push your exported diagrams to a build artifact (name it something like ClassDiagrams).
  2. Add an Azure CLI task to your pipeline (make sure the build service account has Wiki edit permissions):
    • Use this command to update a Wiki page with your diagram (replace placeholders with your org/project/wiki details):
    az devops wiki page update --org https://dev.azure.com/YourOrg --project YourProject --wiki YourWikiName --path "Architecture/Class Diagrams" --content "### Latest Class Diagrams\n\n![Order System Diagram](attachment:OrderSystem.png)\n\n![Customer Service Diagram](attachment:CustomerService.png)" --add-attachments $(Build.ArtifactStagingDirectory)/ClassDiagrams/*.png
    
  3. Alternatively, use a Marketplace extension like Wiki Updater to simplify the process without writing CLI commands.

发布到仪表板

Add your diagrams as visual widgets to your project dashboard:

  1. After publishing diagrams as build artifacts, navigate to your project dashboard.
  2. Click Edit > Add widget, then select the Markdown widget.
  3. In the widget settings, paste a link to your diagram (use the artifact URL, which looks like this):
    ![Order System Diagram](https://dev.azure.com/YourOrg/YourProject/_apis/build/builds/$(Build.BuildId)/artifacts?artifactName=ClassDiagrams&filePath=OrderSystem.png&api-version=7.1-preview.5)
    
    Note: For a permanent link, upload diagrams to Wiki attachments or Azure Blob Storage instead of using build-specific artifact URLs.

发布到项目主页

Customize your project's landing page to display diagrams:

  1. Go to your project homepage, click Customize (top-right).
  2. Add a Markdown section, then embed diagram links the same way you did for the dashboard. You can use the Wiki attachment URLs or permanent storage links for consistency.

关键注意事项

  • Permissions: Ensure the build service account (e.g., YourProject Build Service) has permissions to edit Wiki pages, publish artifacts, and modify dashboard widgets.
  • Consistency: If you have multiple diagrams, use consistent naming conventions to make batch processing and publishing easier.
  • Agent Setup: For the devenv.exe method, confirm your build agent has Visual Studio Build Tools installed with the "Class Designer" workload.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:54:10