Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 5 - The framework 'Microsoft.NETCore.App', version '3.1.0' was not found

When using azure pipelines to build my .NET 5 function I am getting the following error

##[error]/home/vsts/.nuget/packages/microsoft.net.sdk.functions/3.0.11/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error : It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
  - The following frameworks were found:
      5.0.4 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

This also displays a Error : Metadata generation failed error further down the build script

##[error]/home/vsts/.nuget/packages/microsoft.net.sdk.functions/3.0.11/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error : Metadata generation failed.

My build script is

trigger:
- master

stages:

- stage: 'Build'
  jobs:
  - job:
    pool:
      vmImage: 'ubuntu-latest'
    workspace:
      clean: all
    steps:
    - task: UseDotNet@2
      displayName: Use Dot Net Core 5.0.x
      inputs:
        packageType: 'sdk'
        version: '5.0.x'
    - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
        arguments: '--configuration Release'
        command: 'build'
        projects: '**/*.csproj'
like image 981
Kevin Brydon Avatar asked Apr 04 '21 06:04

Kevin Brydon


3 Answers

To build .NET 5 functions, the .NET Core 3 SDK is required. So this must be installed alongside the 5.0.x sdk.

In my case it meant that the script needed to be updated to

trigger:
- master

stages:

- stage: 'Build'
  jobs:
  - job:
    pool:
      vmImage: 'ubuntu-latest'
    workspace:
      clean: all
    steps:
    - task: UseDotNet@2
      displayName: Use Dot Net Core 3.1.x
      inputs:
        packageType: 'sdk'
        version: '3.1.x'
    - task: UseDotNet@2
      displayName: Use Dot Net Core 5.0.x
      inputs:
        packageType: 'sdk'
        version: '5.0.x'
    - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
        arguments: '--configuration Release'
        command: 'build'
        projects: '**/*.csproj'
like image 84
Kevin Brydon Avatar answered Sep 28 '22 20:09

Kevin Brydon


It's a known issue: https://github.com/Azure/azure-functions-dotnet-worker/wiki/Known-issues#net-core-31-dependency

.NET Core 3.1 dependency

When targeting Azure Functions 3.0, by default, the .NET Core 3.1 SDK is required on the machine building the project.
In scenarios where the underlying Azure Functions extension does not have a dependency on native libraries or platform specific assets, and this dependency is undesirable, you can change this behavior by defining the following project property: <_FunctionsExtensionTargetFramework>netstandard2.0</_FunctionsExtensionTargetFramework/>

There's also a github issue.

like image 26
Métoule Avatar answered Sep 28 '22 18:09

Métoule


As David Gardiner suggested, a similar approach works on GitHub Actions.

Below and example of Azure function app with .net 5.

on:
  push:
    branches: [ develop ]

env:
  AZURE_FUNCTIONAPP_NAME: your-functionapp-name  # set this to your application's name
  AZURE_FUNCTIONAPP_PACKAGE_PATH: 'your-package-path'    # set this to the path to your web app project, defaults to the repository root
  DOTNET5_VERSION: '5.0.x'              # set this to the dotnet version to use
  DOTNET3_VERSION: '3.1.x'              # set this to the dotnet version to use

jobs:
  build-and-deploy:
    runs-on: windows-latest
    steps:
    - name: 'Checkout GitHub Action'
      uses: actions/checkout@main

    - name: Setup DotNet ${{ env.DOTNET3_VERSION }} Environment
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: ${{ env.DOTNET3_VERSION }}
        
    - name: Setup DotNet ${{ env.DOTNET5_VERSION }} Environment
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: ${{ env.DOTNET5_VERSION }}
        
    - name: 'Resolve Project Dependencies Using Dotnet'
      shell: pwsh
      run: |
        pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
        dotnet build --configuration Release --output ./output
        popd
    - name: 'Run Azure Functions Action'
      uses: Azure/functions-action@v1
      id: fa
      with:
        app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
        package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
        publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
like image 1
Gaburiere Avatar answered Sep 28 '22 19:09

Gaburiere