4

I just updated my solution to .NET7. I have a build/release pipeline setup on Azure Devops which now fails in the "Restore" step.

This is first error, which is then followed by multiple other errors of the same type:

2:3>Target "_CheckForUnsupportedNETCoreVersion" in file "C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets" from project "D:\a\1\s\xxxx\xxxx.csproj" (target "CollectPackageReferences" depends on it): Using "NETSdkError" task from assembly "C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\targets..\tools\net6.0\Microsoft.NET.Build.Tasks.dll". Task "NETSdkError" 2:3>C:\Program Files\dotnet\sdk\6.0.402\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. [D:\a\1\s\xxxx\xxxx.csproj] Done executing task "NETSdkError" -- FAILED.

I've tried using both "Windows Latest" and "Windows 2022" under "Agent specification" but neither works. I would have thought that "Windows Latest" would get automatically updated to the latest SDK once it's released? What do I have to change to make this build pipeline work with .NET7?

HaukurHaf
  • 13,522
  • 5
  • 44
  • 59
  • See this https://github.com/dotnet/core/issues/7950 – Scott Mildenberger Nov 14 '22 at 21:38
  • @ScottMildenberger Thanks, I actually just read that article and managed to get this to work :) – HaukurHaf Nov 14 '22 at 21:41
  • .Net 7 should be part of the Azure DevOps Hosted Agent (20221111.1) Windows 2022 image should be updated soon hopefully. See PR https://github.com/actions/runner-images/pull/6567 – Julien Jacobs Nov 15 '22 at 11:09
  • Hi ,glad to know you've found the solution to resolve this issue! Please consider answering it and accepting it as an answer to change its status to Answered. Just a reminder :) – Minxin Yu - MSFT Nov 18 '22 at 09:22

3 Answers3

5

I found the solution. I had to add an additional step in the beginning which installs the .NET7 SDK.

enter image description here

HaukurHaf
  • 13,522
  • 5
  • 44
  • 59
4

If pipeline configuration is in YAML an additional task is needed at the beginning:

  - task: UseDotNet@2
    displayName: 'Install .NET Core SDK 7.x'
    inputs:
      version: 7.x
Vlad Rudenko
  • 2,363
  • 1
  • 24
  • 24
1

I had the same issue. But adding just netcore sdk didn't work for me, also added NuGet 6.5.0
enter image description here

 steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 7.x'
  inputs:
    version: 7.x

- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 6.5.0'
  inputs:
    versionSpec: 6.5.0

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\IdentityApp.API.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     !**\obj\**
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
    PublishSymbols: false
  continueOnError: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
    ArtifactName: '$(Parameters.ArtifactName)'
  condition: succeededOrFailed()
Shamith Wimukthi
  • 468
  • 3
  • 12