Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail when targeting to netcoreapp 2.1 and 3.1 using matrix testing #88

Closed
Ceridan opened this issue May 17, 2020 · 1 comment
Closed

Comments

@Ceridan
Copy link

Ceridan commented May 17, 2020

Let me explain the problem. I have a library and tests for it in two separate projects.

Library csproj:

<TargetFramework>netstandard2.0;netcoreapp3.1</TargetFrameworks>

Tests csproj:

<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>

I want to run tests in both LTS versions of netcoreapp 2.1 and 3.1. In case of 2.1 the library should be build as netstandard2.0.

Here is my workflow job:

jobs:
  build-and-test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        dotnet: [
          { framework: netcoreapp2.1, version: 2.1.806 },
          { framework: netcoreapp3.1, version: 3.1.202 }
        ]

    name: ${{ matrix.dotnet.framework }} – build and test

    steps:
      - uses: actions/checkout@master

      - name: Setup dotnet
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version:  ${{ matrix.dotnet.version }}

      - name: Build and tests library
        run: |
          dotnet test --configuration Release --framework ${{ matrix.dotnet.framework }} <path to Tests.csproj>

In this case I have two separate jobs according to matrix. 3.1 successfully completed, but 2.1 is failed on build step with error like this:

[error]/opt/hostedtoolcache/dncs/2.1.806/x64/sdk/2.1.806/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(137,5):
error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1. 
Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [<path to Test.csproj>]

I am a bit stuck how to do it properly? Could you give me some advice?

Actually I have found two workarounds here:

  1. Described in the issue Support installing multiple versions of .NET Core SxS #25 . Do not use matrix and setup both dotnet versions in the one job and use rsync to setup and side by side. The problem here is that your steps becomes sequential instead of parallel steps which would be in matrix testing. Also the job's code becomes more complicated.
  2. Use conditions in csproj. We could describe target frameworks like this:
    Library csproj:
    <TargetFrameworks Condition="'$(Framework)' != 'netcoreapp2.1'">netstandard2.0;netcoreapp3.1</TargetFrameworks>
    <TargetFramework Condition="'$(Framework)' == 'netcoreapp2.1'">netstandard2.0</TargetFramework>

Tests csproj:

    <TargetFrameworks Condition="'$(Framework)' != 'netcoreapp2.1'">netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
    <TargetFramework Condition="'$(Framework)' == 'netcoreapp2.1'">netcoreapp2.1</TargetFramework>

and custom parameter will be added to the dotnet test command:

dotnet test --configuration Release --framework ${{ matrix.dotnet.framework }} <path to Tests.csproj> /p:Framework=${{ matrix.dotnet.framework }}

In this case CI problem affects the entire code base (csproj) which is bad idea I think.

So I am still trying to find better solution.

@ZEisinger
Copy link
Contributor

My understanding is that a library targeted as netstandard2.0 will generally be portable to use with netcoreapp3.1. You should be able to specify just netstandard2.0 in the library and testing could work against both versions. This talks more about multi-target libraries and the cases where this might not work:
https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/cross-platform-targeting

The dotnet team would be the best place to get help with the framework and targetting issues, feel free to reach out to them if you need further advice: https://github.com/dotnet/runtime#filing-issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants