使用 netcoreapp3.1 构建库会在尝试在多个框架上运行测试的 GitHub 操作上引发错误

发布于 2025-01-11 03:34:19 字数 3026 浏览 0 评论 0原文

我正在努力为一个伟大的项目做出贡献(https://github.com/billbogaiv/hybrid -model-binding) - 我想更新目标框架并设置测试。
我的分叉: https://github.com/Misiu/hybrid-model-binding /树/测试
我已将项目从 netstandard2.1 更新到 netcoreapp3.1,一切正常。
所以现在我的解决方案中有 3 个项目:

  • HybridModelBinding - 主库项目
  • AspNetCoreWebApplication - 包含示例的项目
  • HybridModelBinding.UnitTests - 将包含单元测试的项目

我希望我的测试在多个 dotnet 版本上运行,因此我添加了此工作流程:

name: .NET Core
# Trigger event on a push or pull request
on: [push, pull_request]

# Jobs that run in parallel
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet-version: [ '3.1.x','5.0.x', '6.0.x' ]
    # Steps that run sequentially
    steps:
    
    - name: Checkout
      uses: actions/checkout@v2
      
    - name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
      uses: actions/[email protected]
      with:
        dotnet-version: ${{ matrix.dotnet-version }}
        
    - name: Install dependencies
      run: dotnet restore
      
    - name: Build
      run: dotnet build --configuration Release --no-restore
      
    - name: Test
      run: dotnet test --no-restore --verbosity normal

所以理论上一切都应该在 3 个运行时上构建和运行。 第一个构建工作正常(在 3.1.x 上),但第二个和第三个抛出错误:

测试运行 /home/runner/work/混合模型绑定/混合模型绑定/测试/HybridModelBinding.UnitTests/bin/Debug/netcoreapp3.1/HybridModelBinding.UnitTests.dll (.NETCoreApp,版本=v3.1) Microsoft (R) 测试执行命令行 工具版本 16.11.0 版权所有 (c) Microsoft Corporation。版权所有 保留。

开始执行测试,请稍候...共1个测试文件 与指定的模式匹配。 Testhost 进程退出并出现错误:It 无法找到任何兼容的框架版本 找不到框架“Microsoft.AspNetCore.App”,版本“3.1.0”。

测试运行已中止。 3>完成构建项目“/home/runner/work/hybrid-model-binding/hybrid-model-binding/tests/HybridModelBinding.UnitTests/HybridModelBinding.UnitTests.csproj” (VSTest 目标)——失败。 1>完成构建项目“/home/runner/work/hybrid-model-binding/hybrid-model-binding/HybridModelBinding.sln” (VSTest 目标)——失败。

构建失败。

构建摘要: https://github.com/Misiu/hybrid -model-binding/runs/5392702331?check_suite_focus=true

我可以在本地编译项目并运行测试,但我想在 GitHub 上运行它们,因此将来我们可以添加更多测试并更轻松地开发库。

I'm trying to contribute to a great project (https://github.com/billbogaiv/hybrid-model-binding) - I want to update the target framework and set up tests.
My fork: https://github.com/Misiu/hybrid-model-binding/tree/tests
I've updated the project from netstandard2.1 to netcoreapp3.1 and everything works fine.
So now I have 3 projects in the solution:

  • HybridModelBinding - main library project
  • AspNetCoreWebApplication - project with samples
  • HybridModelBinding.UnitTests - project that will contain unit tests

I'd like my tests to run on multiple dotnet versions, so I've added this workflow:

name: .NET Core
# Trigger event on a push or pull request
on: [push, pull_request]

# Jobs that run in parallel
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet-version: [ '3.1.x','5.0.x', '6.0.x' ]
    # Steps that run sequentially
    steps:
    
    - name: Checkout
      uses: actions/checkout@v2
      
    - name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
      uses: actions/[email protected]
      with:
        dotnet-version: ${{ matrix.dotnet-version }}
        
    - name: Install dependencies
      run: dotnet restore
      
    - name: Build
      run: dotnet build --configuration Release --no-restore
      
    - name: Test
      run: dotnet test --no-restore --verbosity normal

So in theory everything should be built and run on 3 runtimes.
The first build works fine (on 3.1.x), but the second and third throw errors:

Test run for
/home/runner/work/hybrid-model-binding/hybrid-model-binding/tests/HybridModelBinding.UnitTests/bin/Debug/netcoreapp3.1/HybridModelBinding.UnitTests.dll
(.NETCoreApp,Version=v3.1) Microsoft (R) Test Execution Command Line
Tool Version 16.11.0 Copyright (c) Microsoft Corporation. All rights
reserved.

Starting test execution, please wait... A total of 1 test files
matched the specified pattern. Testhost process exited with error: It
was not possible to find any compatible framework version The
framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.

Test Run Aborted.
3>Done Building Project "/home/runner/work/hybrid-model-binding/hybrid-model-binding/tests/HybridModelBinding.UnitTests/HybridModelBinding.UnitTests.csproj"
(VSTest target(s)) -- FAILED.
1>Done Building Project "/home/runner/work/hybrid-model-binding/hybrid-model-binding/HybridModelBinding.sln"
(VSTest target(s)) -- FAILED.

Build FAILED.

Build summary: https://github.com/Misiu/hybrid-model-binding/runs/5392702331?check_suite_focus=true

I can compile projects locally and run the tests, but I'd like to run them on GitHub, so in the future, we can add more tests and develop the library easier.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2025-01-18 03:34:19

通过矩阵下的 include 指定目标框架名称 (TFM),并通过添加参数 -f=${{ matrix.tfm 指定 dotnet test 的框架}}

name: .NET Core
# Trigger event on a push or pull request
on: [push, pull_request]

# Jobs that run in parallel
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
        - dotnet-version: '3.1.x'
          tfm: 'netcoreapp3.1'
        - dotnet-version: '5.0.x'
          tfm: 'net5.0'
        - dotnet-version: '6.0.x'
          tfm: 'net6.0'
    # Steps that run sequentially
    steps:
    
    - name: Checkout
      uses: actions/checkout@v2
      
    - name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
      uses: actions/[email protected]
      with:
        dotnet-version: ${{ matrix.dotnet-version }}
        
    - name: Install dependencies
      run: dotnet restore -p:TargetFramework=${{ matrix.tfm }}
      
    - name: Build
      run: dotnet build --configuration Release --no-restore
      
    - name: Test
      run: dotnet test --no-restore --verbosity normal -f=${{ matrix.tfm }}

来源

Specify the Target framework monikers (TFMs) via include under the matrix and specify the framework for dotnet test by adding the argument -f=${{ matrix.tfm }}.

name: .NET Core
# Trigger event on a push or pull request
on: [push, pull_request]

# Jobs that run in parallel
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
        - dotnet-version: '3.1.x'
          tfm: 'netcoreapp3.1'
        - dotnet-version: '5.0.x'
          tfm: 'net5.0'
        - dotnet-version: '6.0.x'
          tfm: 'net6.0'
    # Steps that run sequentially
    steps:
    
    - name: Checkout
      uses: actions/checkout@v2
      
    - name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
      uses: actions/[email protected]
      with:
        dotnet-version: ${{ matrix.dotnet-version }}
        
    - name: Install dependencies
      run: dotnet restore -p:TargetFramework=${{ matrix.tfm }}
      
    - name: Build
      run: dotnet build --configuration Release --no-restore
      
    - name: Test
      run: dotnet test --no-restore --verbosity normal -f=${{ matrix.tfm }}

Sources

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文