The best option is to upgrade to the latest version of the .NET Core or at least to 3.1. For some reason, if you need to stay back to 2.x; you can do so by installing the SDK part of your pipeline tasks.
Please note I have noticed while trying to reproduce your problem that there was a warning message logged that ".NET Core 2.x and 3.0 were removed from all Azure Hosted Pipeline environments" so your option is to
- Use a Self-hosted pipeline (You control everything)
- Azure Hosted Pipeline - Install the required SDK part of pipeline tasks
I have explained a simple YAML pipeline to install the SDK and build 2.X azure functions.
- Download your version of .NET Core 2.x from https://versionsof.net/core/2.1/2.1.0/
- Checkin the EXE to your repo (any path, in this YAML, I used root path)
- Create a YAML pipeline as shown below (you can copy-paste the lines)
- Add CommandLine task to install the .NET SDK in silent mode
- Run the pipeline
trigger:
- master
variables:
Agent VM image name
vmImageName: 'windows-2022'
Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/FunctionApp2'
stages:
- stage: Build
displayName: Build stage jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName) steps:
- task: CmdLine@1 displayName: 'Install SDK' inputs: filename: '$(Build.SourcesDirectory)\dotnet-sdk-2.1.300-win-x64.exe' arguments: /install /quiet /norestart
- task: DotNetCoreCLI@2 displayName: Build inputs: command: 'build' projects: | $(workingDirectory)/*.csproj arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release
- task: ArchiveFiles@2 displayName: 'Archive files' inputs: rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output' includeRootFolder: false archiveType: zip archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip artifact: drop
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName) steps: