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

GitHub Action中.NET项目跨平台构建耗时对比及Windows优化咨询

关于.NET项目GitHub Action跨平台构建耗时差异的问题

各平台构建耗时

OS构建耗时
win-x641分45秒
osx-x6443秒
linux-x6448秒

当前GitHub Action配置

name: Build and Release

on:
  workflow_dispatch: 

permissions:
  contents: write

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [windows-latest, macos-latest, ubuntu-latest]

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.0.x'

      - name: Restore dependencies
        run: dotnet restore src

      - name: Publish project
        run: |
          dotnet publish ./src/MyProject -c Release -r ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'macos-latest' && 'osx-x64' || 'linux-x64'}} --self-contained -o ./publish/${{ matrix.os }} /p:Version=${{ env.VERSION }}
        env:
          DOTNET_CLI_TELEMETRY_OPTOUT: 1

耗时差异观察

Linux和macOS的构建耗时差距不大,但Windows耗时至少是它们的两倍,主要在以下环节落后明显:

  • .NET环境配置
  • 依赖还原
  • 项目构建/发布

构建环节耗时对比截图

疑问与优化需求

  1. 推测Ubuntu已预装.NET 8,因此跳过了.NET环境配置环节,耗时为0秒。但为何macOS仅需7秒而Windows却需要17秒来配置.NET?
  2. Linux和macOS的依赖还原与构建耗时相近,但Windows却大幅落后,原因是什么?
  3. 是否有针对Windows构建场景的优化方法?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 15:08:18