DevOps pipeline CI error when I updated .net core 3.1 to .net core 6

Viewed 635

So I updated all the projects of my solution to .net core 6, before every single one was .net core 3.1.

Then I started to get the following error in build step:

##[error]PjInspe.Tests\PjInspe.Tests.csproj(0,0): Error NU1201: 
Project PjInspe.Aplicacao is not compatible with netcoreapp3.1 
(.NETCoreApp,Version=v3.1). Project PjInspe.Aplicacao supports: 
net6.0 (.NETCoreApp,Version=v6.0)

But all the projects has this in the .csproj

enter image description here

And its the only project that is failing

Any ideas how to solve this?

EDIT:

My pipeline YAML

Iam using the windows 2022 to run the CI and I've seen the sdk from the net6 on the build logs

pool:
  name: Azure Pipelines

steps:
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: '**/*Project.csproj'
    vstsFeed: '***************'

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.RestoreBuildProjects)'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '$(Parameters.TestProjects)'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()
1 Answers

The right way is supposted to be to modify you dotnetcore cli task as follows

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    version: '6.0.x' //better to put this in a variable
    projects: '$(Parameters.TestProjects)'
    arguments: '--configuration $(BuildConfiguration)'

But I still had a similar build problem. I fixed it by using the use dotnet core task BEFORE all other tasks and specifying the version I need. enter image description here

This is the yaml code that I used

 - task: UseDotNet@2
      displayName: 'Use .NET 6 Core sdk'
      inputs:
        packageType: 'sdk'
        version: '6.0.x' 
Related