GitHub Action中.NET项目跨平台构建耗时对比及Windows优化咨询
关于.NET项目GitHub Action跨平台构建耗时差异的问题
各平台构建耗时
| OS | 构建耗时 |
|---|---|
| win-x64 | 1分45秒 |
| osx-x64 | 43秒 |
| linux-x64 | 48秒 |
当前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环境配置
- 依赖还原
- 项目构建/发布

疑问与优化需求
- 推测Ubuntu已预装.NET 8,因此跳过了.NET环境配置环节,耗时为0秒。但为何macOS仅需7秒而Windows却需要17秒来配置.NET?
- Linux和macOS的依赖还原与构建耗时相近,但Windows却大幅落后,原因是什么?
- 是否有针对Windows构建场景的优化方法?
内容的提问来源于stack exchange,提问作者tridy
相关产品推荐
相关产品推荐

