Azure function build pipeline fails and getting error i.e. Microsoft.NET.Sdk.Functions.Build.targets(41,5): Error : You must install or update .NET to run this

Mandil, Anshul (Cognizant) 1 Reputation point
2022-08-14T16:30:09.85+00:00

I have deployed the my changes to azure function and deployed for the same but while building pipeline it fails in build solution activity . Given below is the detail,

Below is the version currently using,

Visual studio : 2019
.Net core framework : 2.1
microsoft.net.SDK.function : 1.029
Agent pool : Azure pipelines
Agent specification : windows-latest

Below is the error:

C:\Users\VssAdministrator.nuget\packages\microsoft.net.sdk.functions\1.0.29\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): Error : You must install or update .NET to run this application. App: C:\Users\VssAdministrator.nuget\packages\microsoft.net.sdk.functions\1.0.29\tools\netcoreapp2.1\Microsoft.NET.Sdk.Functions.Generator.dll Architecture: x64 Framework: 'Microsoft.NETCore.App', version '2.1.0' (x64) .NET location: C:\Program Files\dotnet\ The following frameworks were found: 3.1.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 3.1.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 3.1.20 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 3.1.26 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 3.1.27 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 5.0.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 5.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 5.0.17 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 6.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 6.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Learn about framework resolution: https://aka.ms/dotnet/app-launch-failed To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.0&arch=x64&rid=win10-x64

Please provide the solution for the same as soon as possible

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,314 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Udaiappa Ramachandran 726 Reputation points MVP
    2022-08-16T18:33:41.43+00:00

    @Mandil, Anshul (Cognizant)

    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

    1. Use a Self-hosted pipeline (You control everything)
    2. 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.

    1. Download your version of .NET Core 2.x from https://versionsof.net/core/2.1/2.1.0/
    2. Checkin the EXE to your repo (any path, in this YAML, I used root path)
    3. Create a YAML pipeline as shown below (you can copy-paste the lines)
    4. Add CommandLine task to install the .NET SDK in silent mode
    5. 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
    0 comments No comments