'Library build with netcoreapp3.1 throws errors on GitHub actions trying to run tests on multiple frameworks
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.
- The following frameworks were found: 5.0.14 at [/home/runner/.dotnet/shared/Microsoft.AspNetCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=ubuntu.20.04-x64 . Please check the diagnostic logs for more information.
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.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
