2

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 Files\dotnet\sdk\6.0.203\Sdks\Microsoft.NET.Sdk\targets\Microsoft.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.

devendar
  • 53
  • 4

2 Answers2

2

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

silent
  • 14,494
  • 4
  • 46
  • 86
  • Hi I have tried YAML script as above, I am getting the below error message [error]C:\hostedtoolcache\windows\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): Error NETSDK1004: Assets file 'D:\a\1\s\ExPro Core\ExProModel.Model.Server\obj\project.assets.json' not found. 2) Run a NuGet package restore to generate this file. – devendar Dec 20 '22 at 07:52
  • And I assume you have followed the instruction and ran `dotnet restore`?! – silent Dec 20 '22 at 08:53
  • - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' – devendar Dec 20 '22 at 09:01
  • - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' – devendar Dec 20 '22 at 09:02
  • restore and build scripts are above – devendar Dec 20 '22 at 09:02
  • please paste your entire relevant pipeline code in your question post – silent Dec 20 '22 at 09:40
1

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\_tool\dotnet\sdk\7.0.102\Sdks

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  
Mr Moose
  • 5,946
  • 7
  • 34
  • 69