subi_speedrunner
subi_speedrunner

Reputation: 921

Github Actions - Using Matrix with .Net Core SDK

I have created a strategy/matrix where I am trying to build the project in different environ.

Please find below the workflow yml file:

  jobs:
  job_name_is_build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet-version: ["3.0", "3.1.x", "5.0.x"]
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: Set up .Net Core SDK ${{ matrix.dotnet-version }}
        uses: actions/[email protected]
        with:
          dotnet-version: ${{ matrix.dotnet-version }}
      - name: Display .net verion
        run: dotnet --version
      - name: Install Newtonsoft package
        run: dotnet add WebApplication1/WebApplication1.csproj package Newtonsoft.Json --version 12.0.1
      - name: Install dependencies
        run: dotnet restore
      - name: Build Solution
        run: dotnet build --configuration Release --no-restore
      - name: Run Unit Tests
        run: dotnet test --no-restore --verbosity normal

I have created a .Net Core 5.0 project template.

<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

Now, When the workflow runs in Github actions, I am getting error in build step:

The reference assemblies for ".NETFramework,Version=v5.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.

Now, my query is whether it is possible to run the application with different SDK. For Ex: My project is in .Net core 5, So the same project I cannot build with .Net Core 3.1 using strategy/matrix ?

Upvotes: 1

Views: 543

Answers (2)

omajid
omajid

Reputation: 15213

You could use the --framework argument to dotnet restore/build/test to override the TargetFramework:

dotnet build --configuration Release --no-restore --framework netcoreapp3.0
dotnet build --configuration Release --no-restore --framework netcoreapp3.1
dotnet build --configuration Release --no-restore --framework net5.0

You could add these to your matrix declaration.

Upvotes: 1

Krzysztof Madej
Krzysztof Madej

Reputation: 40749

.NET 5.0 know about dotnet core 3.1 but not the other way. So, if you have on your machine installed .NET 5.0 you should be able to build application which is targeted to 3.1, bot not the other way.

But, this not not only a matter of this <TargetFramework>net5.0</TargetFramework>, because your dependencies may also be compiled to a fixed version in your case .net 5. In you case it is not possible to compile .NET 5.0 app against these sdk's: ["3.0", "3.1.x"].

Please check also this.

Upvotes: 1

Related Questions