I believe you have issues with your pipeline tasks, make sure agent is set to Windows 2022 for YAML
pool:
vmImage: 'windows-2022'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$newBuildNumber = echo ($(PSVBUILDNUMBER)+$(PSVBUILDVERSION))
((Get-Content -path Directory.Build.props -Raw) -replace 'BUILD_NUMBER', $newBuildNumber) | Set-Content -Path Directory.Build.props
workingDirectory: '$(Build.Repository.LocalPath)' - task: PowerShell@2
inputs:
targetType: 'inline'
script: Get-Content -path Directory.Build.props -Raw
workingDirectory: '$(Build.Repository.LocalPath)' - task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)' - task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '[YOUR BUILD ARGS]'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)' - task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)' - task: CopyFiles@2
displayName: 'Copying files'
condition: and(succeeded(), true)
inputs:
Contents: '[PROJECT PATH]/bin/**'
TargetFolder: '$(Build.ArtifactStagingDirectory)/[WHATEVER-PATH]'
and if your pipeline uses GUI then set SDK to 6.0.102 or later version, please refer the screen shot