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

.NET 7升级后Azure Pipeline中.NET Core Publish任务过慢问题

Blazor WebAssembly托管项目升级.NET 7后Azure Pipeline发布耗时激增的解决办法

把Blazor WebAssembly托管项目从.NET 6升级到.NET 7后,Azure Pipeline里的.NET Core Publish任务耗时直接暴涨——原来.NET 6环境下不到8分钟搞定,升级后直接超50分钟,还经常因为60分钟超时限制失败。试过windows-latest和ubuntu-latest代理都没改善,当前发布步骤的YAML配置如下:

#Your build pipeline references an undefined variable named ‘BuildConfiguration’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

steps:
- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: false
    projects: '**/Server/Agfund.Server.csproj'
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    zipAfterPublish: True

目前确认瓶颈是程序集文件优化环节过慢,给你几个实用的解决办法:

  • 临时禁用Wasm程序集优化(快速解决超时)
    在Server项目的.csproj文件里加以下配置,发布时跳过AOT编译和程序集压缩:

    <PropertyGroup>
      <BlazorEnableCompression>false</BlazorEnableCompression>
      <RunAOTCompilation>false</RunAOTCompilation>
    </PropertyGroup>
    

    注意:这么做会让前端程序集体积变大、加载速度略降,但能立刻把发布时间压下来,先解决CI超时问题再说。

  • 优化发布命令参数
    如果你的Pipeline里已经单独做了restore和build步骤,给Publish命令加--no-restore和--no-build,避免重复执行这些操作:

    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory) --no-restore --no-build'
    

    另外,禁用Blazor的链接优化也能减少处理时间(代价是程序集体积变大),加参数/p:BlazorWebAssemblyEnableLinking=false:

    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory) /p:BlazorWebAssemblyEnableLinking=false'
    
  • 提升代理资源规格
    微软默认托管代理的CPU和内存都有限,程序集优化是吃CPU的活儿,换成更大规格的代理(比如windows-2022配更高配置,或者用自己的自托管代理),能明显缩短优化时间。

  • 拆分Client和Server的发布步骤
    别在一个Publish任务里同时处理Client和Server,分开发布:

    # 先发布Blazor Client
    - task: DotNetCoreCLI@2
      displayName: Publish Blazor Client
      inputs:
        command: publish
        projects: '**/Client/Agfund.Client.csproj'
        arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)/Client'
        zipAfterPublish: False
    
    # 再发布Server
    - task: DotNetCoreCLI@2
      displayName: Publish Server
      inputs:
        command: publish
        projects: '**/Server/Agfund.Server.csproj'
        arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)/Server'
        zipAfterPublish: True
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 21:23:40