skip to Main Content

Unable to build the ASP.Net Core 7 in azure devops pipeline (CI), Using Classic pipeline and ASP.net core template

Error message :

##[error]C:Program Filesdotnetsdk6.0.203SdksMicrosoft.NET.SdktargetsMicrosoft.NET.TargetFrameworkInference.targets(144,5)
: Error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0.
Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0.

2

Answers


  1. Add a task to install the .NET version that you need (you can change 7.x to something more specific)

      - task: UseDotNet@2
        displayName: 'Use .NET Core SDK 7.x'
        inputs:
          packageType: sdk
          version: '7.x'
          installationPath: $(Agent.ToolsDirectory)/dotnet
    

    Docs

    Login or Signup to reply.
  2. We faced this same issue in upgrading to .NET 7 on our self hosted agents, and despite adding the UseDotNet@2 as described by silent, we still ended up with failures referencing various 6.0.x SDK targets.

    The issue ended up being resolved through this answer. It was due to a previous install of .NET 6 and the variable MSBuildSDKsPath. If you have self hosted agents, check the "Capabilities" of the agent to show the variable itself.

    Failing that, check the value of that through the pipeline itself with a step like;

          - script: set
            displayName: show all env vars
    

    An example snippet of our ci-pipeline.yaml that worked is as follows. Important notes are MSBuildSDKsPath overriding whatever environment variable is set on the agent to reflect the location of the newly installed .NET 7 SDK;

    trigger:
      branches:
        include:
        - '*'
        exclude:
        - develop
        - main
    
    variables:
      - name: solution
        value: '**/*.sln'  
      - name: BuildConfiguration
        value: 'Release'
      - name: MSBuildSDKsPath
        value: C:agent_work_tooldotnetsdk7.0.102Sdks
    
    jobs:
      - job: Build
        pool:
          vmImage: 'windows-latest'
          name: 'Modern'
        workspace:
          clean: all
    
        steps:
          - script: set
            displayName: show all env vars
    
          - checkout: self
            persistCredentials: true
    
          - task: UseDotNet@2
            displayName: 'Use .NET 7.x'
            inputs:
              packageType: 'sdk'
              version: 7.x
              performMultiLevelLookup: true
              includePreviewVersions: false
              installationPath: $(Agent.ToolsDirectory)/dotnet  
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search