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

GitHub Actions多框架测试失败求助(net472/net10.0-windows)

解决GitHub Actions中多框架测试执行报错的问题

针对net472框架(Ubuntu环境缺少Mono)

  • 在Ubuntu运行器的工作流步骤中,先安装Mono组件:
    sudo apt-get update && sudo apt-get install -y mono-devel
    
  • 安装完成后,dotnet test会自动检测并使用Mono运行.NET Framework项目,无需额外切换命令。

针对net10.0-windows框架(Ubuntu找不到WindowsDesktop.App)

  • .NET Windows Desktop框架仅支持Windows环境,Linux系统无法运行该框架的项目。需要给不同框架分配对应运行器:
    • net8.0、net10.0(非Windows特定)继续用ubuntu-latest;
    • net472可选择ubuntu-latest(搭配Mono)或直接用windows-latest;
    • net10.0-windows必须用windows-latest。
  • 修改工作流文件.github/workflows/CodeCoverage.yaml,用矩阵策略分环境执行:
    jobs:
      test:
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            os: [ubuntu-latest, windows-latest]
            framework:
              - net8.0
              - net10.0
              - ${{ if eq(matrix.os, 'windows-latest') }}net472{{ endif }}
              - ${{ if eq(matrix.os, 'windows-latest') }}net10.0-windows{{ endif }}
            exclude:
              - os: ubuntu-latest
                framework: net472
              - os: ubuntu-latest
                framework: net10.0-windows
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
          - name: Setup .NET
            uses: actions/setup-dotnet@v4
            with:
              dotnet-version: '10.0.x'
          - name: Install Mono (Ubuntu only)
            if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net472'
            run: sudo apt-get update && sudo apt-get install -y mono-devel
          - name: Run tests
            run: dotnet test --framework ${{ matrix.framework }} --collect:"XPlat Code Coverage"
    

额外注意事项

  • Windows运行器默认已包含net472所需的.NET Framework,actions/setup-dotnet会自动安装.NET 10 SDK,无需额外配置。
  • 若坚持在Ubuntu运行net472,需确认测试项目无Windows专属API依赖,避免Mono兼容问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.11 14:03:11